Interrupt connections outside the lock.

This commit is contained in:
akwizgran
2020-05-13 10:24:27 +01:00
parent 1b2b50d91b
commit 8dd993dd9d

View File

@@ -32,6 +32,7 @@ class ConnectionChooserImpl implements ConnectionChooser {
@Override @Override
public void addConnection(ContactId c, TransportId t, public void addConnection(ContactId c, TransportId t,
DuplexSyncConnection conn, Priority p) { DuplexSyncConnection conn, Priority p) {
DuplexSyncConnection close = null;
synchronized (lock) { synchronized (lock) {
Key k = new Key(c, t); Key k = new Key(c, t);
Value best = bestConnections.get(k); Value best = bestConnections.get(k);
@@ -39,12 +40,14 @@ class ConnectionChooserImpl implements ConnectionChooser {
bestConnections.put(k, new Value(conn, p)); bestConnections.put(k, new Value(conn, p));
} else if (compare(p.getNonce(), best.priority.getNonce()) > 0) { } else if (compare(p.getNonce(), best.priority.getNonce()) > 0) {
LOG.info("Found a better connection"); LOG.info("Found a better connection");
close = best.connection;
bestConnections.put(k, new Value(conn, p)); bestConnections.put(k, new Value(conn, p));
best.connection.interruptOutgoingSession(); } else {
LOG.info("Already have a better connection");
close = conn;
} }
LOG.info("Already have a better connection");
conn.interruptOutgoingSession();
} }
if (close != null) close.interruptOutgoingSession();
} }
@Override @Override