Skip to content

Commit

Permalink
closeHandler has to be registered before connection close
Browse files Browse the repository at this point in the history
Signed-off-by: Wetitpig <[email protected]>
  • Loading branch information
Wetitpig committed Dec 7, 2023
1 parent 398cfa2 commit 73bb10a
Showing 1 changed file with 8 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,14 @@ private MaxConnectionsHandler() {}
public static Handler<HttpConnection> 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(
Expand All @@ -45,14 +53,6 @@ public static Handler<HttpConnection> handler(
activeConnectionsCount.incrementAndGet(),
maxActiveConnections);
}
connection.closeHandler(
c ->
LOG.debug(
"Connection closed from {} to {}. Total of active connections: {}/{}",
connection.remoteAddress(),
connection.localAddress(),
activeConnectionsCount.decrementAndGet(),
maxActiveConnections));
};
}
}

0 comments on commit 73bb10a

Please sign in to comment.