Skip to content

Commit

Permalink
Ensure the post-process of a response is executed without a local req…
Browse files Browse the repository at this point in the history
…uest context (#4527)

Motivation:

A listener of a `ChannelFuture` can have a different request context in the thread local. Because Netty handles some pending requests in a batch task with an event loop having the different request context.

Modifications:

- Remove a request context from thread local before invoking `tryComplete()`

Result:

Fixed a potential `RequestContext` leak when an incomplete `HttpResponse` is returned.
  • Loading branch information
ikhoon authored Nov 10, 2022
1 parent ab20641 commit 0930b18
Showing 1 changed file with 5 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,11 @@ public void onComplete() {
if (oldState == State.NEEDS_HEADERS) {
logger.warn("{} Published nothing (or only informational responses): {}", ctx.channel(), service());
responseEncoder.writeReset(req.id(), req.streamId(), Http2Error.INTERNAL_ERROR)
.addListener(future -> tryComplete(null));
.addListener(future -> {
try (SafeCloseable ignored = RequestContextUtil.pop()) {
tryComplete(null);
}
});
ctx.flush();
return;
}
Expand Down

0 comments on commit 0930b18

Please sign in to comment.