Skip to content

Commit

Permalink
fix: try harder to decrement CurrentByHostname metric
Browse files Browse the repository at this point in the history
  • Loading branch information
Tasssadar committed Mar 20, 2023
1 parent f70c27c commit ff52c13
Showing 1 changed file with 12 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,14 @@ public <ReqT, RespT> ServerCall.Listener<ReqT> interceptCall(final ServerCall<Re
final AtomicInteger currentCalls = cache.getGaugedValueByHostname(method, "CurrentByHostname");
final Instant start = clock.instant();

CurrentCallsReleaser currentCallsReleaser;
currentCalls.incrementAndGet();
final CurrentCallsReleaser currentCallsReleaser = new CurrentCallsReleaser(currentCalls);
try {
currentCallsReleaser = new CurrentCallsReleaser(currentCalls);
} catch(Throwable ex) {
currentCalls.decrementAndGet();
throw ex;
}

final ServerCall<ReqT, RespT> newCall = new ForwardingServerCall.SimpleForwardingServerCall<ReqT, RespT>(call) {
@Override
Expand Down Expand Up @@ -113,5 +119,10 @@ void release() {
currentCalls.decrementAndGet();
}
}

@Override
protected void finalize() {
release();
}
}
}

0 comments on commit ff52c13

Please sign in to comment.