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.
|
* @param reason motivo do encerramento informado aos peers.
|
||||||
*/
|
*/
|
||||||
public void closeAllConnections(String reason) {
|
public void closeAllConnections(String reason) {
|
||||||
for (List<TcpConnection> connections : privateConnections.values()) {
|
synchronized (privateConnections) {
|
||||||
for (TcpConnection connection : connections) {
|
for (List<TcpConnection> connections : new ArrayList<>(privateConnections.values())) {
|
||||||
InfoMessage.sendSystemInfo(connection, InfoType.CONNECTION_CLOSED, reason);
|
for (TcpConnection connection : new ArrayList<>(connections)) {
|
||||||
|
InfoMessage.sendSystemInfo(connection, InfoType.CONNECTION_CLOSED, reason);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
closeAllConnections();
|
closeAllConnections();
|
||||||
@@ -221,18 +223,19 @@ class TcpConnectionManager implements PeerListener {
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
public void closeAllConnections() {
|
public void closeAllConnections() {
|
||||||
for (TcpConnection connection : publicConnections.values()) {
|
for (TcpConnection connection : new ArrayList<>(publicConnections.values())) {
|
||||||
closeConnection(connection);
|
closeConnection(connection);
|
||||||
}
|
}
|
||||||
|
|
||||||
synchronized (privateConnections) {
|
synchronized (privateConnections) {
|
||||||
for (List<TcpConnection> connectionsList : privateConnections.values()) {
|
for (List<TcpConnection> connectionsList : new ArrayList<>(privateConnections.values())) {
|
||||||
for (TcpConnection connection : connectionsList) {
|
for (TcpConnection connection : new ArrayList<>(connectionsList)) {
|
||||||
closeConnection(connection);
|
closeConnection(connection);
|
||||||
}
|
}
|
||||||
privateConnections.clear();
|
|
||||||
}
|
}
|
||||||
|
privateConnections.clear();
|
||||||
}
|
}
|
||||||
|
publicConnections.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Reference in new issue
Block a user