-
Notifications
You must be signed in to change notification settings - Fork 1k
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: concurrency bug when doing high volume pull query over java client (alternative) #10077
fix: concurrency bug when doing high volume pull query over java client (alternative) #10077
Conversation
|
1 similar comment
|
@@ -97,12 +99,6 @@ public PullQueryWriteStream( | |||
) { | |||
this.queryLimit = queryLimit; | |||
this.translator = translator; | |||
|
|||
// register a drainHandler that will wake up anyone waiting on hasCapacity |
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.
I don't see how this is necessary, since every time we call the drain handlers, we anyways acquire the monitor.
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.
LGTM!
@@ -211,6 +207,7 @@ private PullQueryRow pollRow() { | |||
if (monitor.enterIf(atHalfCapacity)) { | |||
try { | |||
drainHandler.forEach(h -> h.handle(null)); | |||
drainHandler.clear(); |
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.
It seems like other implementors only allow one handler at a time, and they just clobber any previous one rather than keeping a list, but I couldn't find good documentation on this.
I also think proper callers also reregister after every callback they get, but I couldn't find a very good documentation of this either.
Ultimately, the only user of these APIs are the http response objects, so if we test it out with them, we're good.
Description
Fix for a race inside vert.x’s
RecordParser
. Two threads are hittingRecordParserImpl.handleParsing
, one is entering from upstream viaRecordParser.handle
, and one thread is coming from the downstream viaReadStream.resume
. Once ourPullQueryWriteStream
is half empty, we call the drain handler, which callsRecordParser.resume
, which synchronously starts parsing new records from the buffer.RecordParser.handleParsing
is not thread-safe.The cause is that the monitor inside
PullQueryWriteStream
is insufficient to protect from races inside theRecordParser
. This makes two changes:ReadStream
context, which ensures that it is race-free with other calls intoRecordParser
since it's executed as part of the same netty event loop.PipeImpl
will re-register the drain handler when theWriteStream
reaches capacity.Testing done
No behavior changes in existing integration tests. Tested locally.
Reviewer checklist