-
Notifications
You must be signed in to change notification settings - Fork 921
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix race condition where log.whenComplete
may not complete
#5986
Conversation
if (!hasInterestedFlags(deferredFlags, RequestLogProperty.REQUEST_CONTENT) || | ||
isAvailable(RequestLogProperty.REQUEST_CONTENT)) { | ||
// Set names if request content is not deferred | ||
if (!hasInterestedFlags(deferredFlags, RequestLogProperty.REQUEST_CONTENT)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Previously, the default name was filled in if there was no custom value before a request ended. With this change, if a deferred request content is called before endRequest()
, RequestLogBuilder.name()
could be ignored, which may be a breaking change. Would it be worth specifying this change in Javadoc?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure, done
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The change makes sense. 👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks!
Motivation: It has been reported that `log.whenComplete` is not completing in some cases in #5981. The cause seems to be a race condition between `DefaultRequestLog#endRequest` and `DefaultRequestLog#requestContent`. Completion of `log.whenComplete` is important because 1) it is semantically bound to an HTTP request 2) users (including us) have clean up logic using `log.whenComplete`. I propose that simply `endRequest` only sets `name` if content is not deferred, and `requestContent` sets `name` if content is deferred. The logic is easier to reason about, and there are minimal performance implications since a lock is held anyways. Modifications: - `#endRequest` sets `name` if `requestContent` isn't deferred - `#requestContent` sets name if `requestContent` is deferred Result: - Closes #5981 <!-- Visit this URL to learn more about how to write a pull request description: https://armeria.dev/community/developer-guide#how-to-write-pull-request-description -->
Motivation:
It has been reported that
log.whenComplete
is not completing in some cases in #5981.The cause seems to be a race condition between
DefaultRequestLog#endRequest
andDefaultRequestLog#requestContent
. Completion oflog.whenComplete
is important becauselog.whenComplete
.I propose that simply
endRequest
only setsname
if content is not deferred, andrequestContent
setsname
if content is deferred. The logic is easier to reason about, and there are minimal performance implications since a lock is held anyways.Modifications:
#endRequest
setsname
ifrequestContent
isn't deferred#requestContent
sets name ifrequestContent
is deferredResult:
FramedGrpcService
withctx.log.whenComplete
Not Completing in v1.30.1 #5981