Skip to content

Commit

Permalink
Ensure active connections is decremented (#2335)
Browse files Browse the repository at this point in the history
This PR is an improvement for #2237.
When the AbstractHttpServerMetricsHandler.write method is getting an exception thrown by recordWrite, then the recordInactiveConnection is never called. So, this is too bad because the long adder for the active connection is then never decremented by the missed call to recordInactiveConnection, resulting in leaving the number of active connections to an inconsistent value.

Fixes #2187
  • Loading branch information
pderop committed Jun 28, 2022
1 parent 06dc577 commit d1b94b8
Showing 1 changed file with 18 additions and 12 deletions.
Expand Up @@ -112,24 +112,30 @@ public void write(ChannelHandlerContext ctx, Object msg, ChannelPromise promise)

if (msg instanceof LastHttpContent) {
promise.addListener(future -> {
try {
ChannelOperations<?, ?> channelOps = ChannelOperations.get(ctx.channel());
if (channelOps instanceof HttpServerOperations) {
HttpServerOperations ops = (HttpServerOperations) channelOps;
ChannelOperations<?, ?> channelOps = ChannelOperations.get(ctx.channel());
if (channelOps instanceof HttpServerOperations) {
HttpServerOperations ops = (HttpServerOperations) channelOps;
try {
recordWrite(ops, uriTagValue == null ? ops.path : uriTagValue.apply(ops.path),
ops.method().name(), ops.status().codeAsText().toString());
if (!ops.isHttp2() && ops.hostAddress() != null) {
// This metric is not applicable for HTTP/2
// ops.hostAddress() == null when request decoding failed, in this case
// we do not report active connection, so we do not report inactive connection
}
catch (RuntimeException e) {
log.warn("Exception caught while recording metrics.", e);
// Allow request-response exchange to continue, unaffected by metrics problem
}
if (!ops.isHttp2() && ops.hostAddress() != null) {
// This metric is not applicable for HTTP/2
// ops.hostAddress() == null when request decoding failed, in this case
// we do not report active connection, so we do not report inactive connection
try {
recordInactiveConnection(ops);
}
catch (RuntimeException e) {
log.warn("Exception caught while recording metrics.", e);
// Allow request-response exchange to continue, unaffected by metrics problem
}
}
}
catch (RuntimeException e) {
log.warn("Exception caught while recording metrics.", e);
// Allow request-response exchange to continue, unaffected by metrics problem
}

dataSent = 0;
});
Expand Down

0 comments on commit d1b94b8

Please sign in to comment.