- connections.remove(conn.cookie(), conn);
- LOG.debug("{}: removed connection {}", persistenceId(), conn);
+ final long stamp = connectionsLock.writeLock();
+ try {
+ if (!connections.remove(conn.cookie(), conn)) {
+ final AbstractClientConnection<T> existing = connections.get(conn.cookie());
+ if (existing != null) {
+ LOG.warn("{}: failed to remove connection {}, as it was superseded by {}", persistenceId(), conn,
+ existing);
+ } else {
+ LOG.warn("{}: failed to remove connection {}, as it was not tracked", persistenceId(), conn);
+ }
+ } else {
+ LOG.info("{}: removed connection {}", persistenceId(), conn);
+ }
+ } finally {
+ connectionsLock.unlockWrite(stamp);
+ }