fix(tcp): evitar ConcurrentModificationException ao fechar todas as conexões
Itera cópias das listas de conexões públicas/privadas antes de remover no shutdown. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
1 parent
d0e9573e72
commit
ef33245f49
1 file changed
+10
-7
@@ -205,9 +205,11 @@ class TcpConnectionManager implements PeerListener {
|
||||
* @param reason motivo do encerramento informado aos peers.
|
||||
*/
|
||||
public void closeAllConnections(String reason) {
|
||||
for (List<TcpConnection> connections : privateConnections.values()) {
|
||||
for (TcpConnection connection : connections) {
|
||||
InfoMessage.sendSystemInfo(connection, InfoType.CONNECTION_CLOSED, reason);
|
||||
synchronized (privateConnections) {
|
||||
for (List<TcpConnection> connections : new ArrayList<>(privateConnections.values())) {
|
||||
for (TcpConnection connection : new ArrayList<>(connections)) {
|
||||
InfoMessage.sendSystemInfo(connection, InfoType.CONNECTION_CLOSED, reason);
|
||||
}
|
||||
}
|
||||
}
|
||||
closeAllConnections();
|
||||
@@ -221,18 +223,19 @@ class TcpConnectionManager implements PeerListener {
|
||||
*/
|
||||
|
||||
public void closeAllConnections() {
|
||||
for (TcpConnection connection : publicConnections.values()) {
|
||||
for (TcpConnection connection : new ArrayList<>(publicConnections.values())) {
|
||||
closeConnection(connection);
|
||||
}
|
||||
|
||||
synchronized (privateConnections) {
|
||||
for (List<TcpConnection> connectionsList : privateConnections.values()) {
|
||||
for (TcpConnection connection : connectionsList) {
|
||||
for (List<TcpConnection> connectionsList : new ArrayList<>(privateConnections.values())) {
|
||||
for (TcpConnection connection : new ArrayList<>(connectionsList)) {
|
||||
closeConnection(connection);
|
||||
}
|
||||
privateConnections.clear();
|
||||
}
|
||||
privateConnections.clear();
|
||||
}
|
||||
publicConnections.clear();
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in new issue
Block a user