diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/handlers/MaxConnectionsHandler.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/handlers/MaxConnectionsHandler.java index 42c4158c4e9..b4298e4a42f 100644 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/handlers/MaxConnectionsHandler.java +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/handlers/MaxConnectionsHandler.java @@ -29,6 +29,14 @@ private MaxConnectionsHandler() {} public static Handler handler( final AtomicInteger activeConnectionsCount, final int maxActiveConnections) { return connection -> { + connection.closeHandler( + c -> + LOG.debug( + "Connection closed from {} to {}. Total of active connections: {}/{}", + connection.remoteAddress(), + connection.localAddress(), + activeConnectionsCount.decrementAndGet(), + maxActiveConnections)); if (activeConnectionsCount.get() >= maxActiveConnections) { // disallow new connections to prevent DoS LOG.warn( @@ -45,14 +53,6 @@ public static Handler handler( activeConnectionsCount.incrementAndGet(), maxActiveConnections); } - connection.closeHandler( - c -> - LOG.debug( - "Connection closed from {} to {}. Total of active connections: {}/{}", - connection.remoteAddress(), - connection.localAddress(), - activeConnectionsCount.decrementAndGet(), - maxActiveConnections)); }; } }