Repository navigation
Fix NPE in AbstractNioChannel.removeReadOp() after concurrent deregistration - #17104
normanmaurer merged 3 commits into
Conversation
…tration
Motivation:
clearReadPending() guards the scheduling of clearReadPendingRunnable with an
isRegistered() check, which reads the "registered" boolean of AbstractChannel.
That boolean and the IoRegistration field of AbstractNioChannel are not updated
atomically together. When a channel is deregistered from a different thread after
the isRegistered() check passed but before the runnable executes on the EventLoop,
doDeregister() has already set the registration field to null. removeReadOp() then
called registration() (which returns the field after an assert) and dereferenced it,
producing a NullPointerException (or an AssertionError when assertions are enabled):
java.lang.NullPointerException
at io.netty.channel.nio.AbstractNioChannel$AbstractNioUnsafe.removeReadOp(AbstractNioChannel.java:268)
at io.netty.channel.nio.AbstractNioChannel.clearReadPending0(AbstractNioChannel.java:223)
at io.netty.channel.nio.AbstractNioChannel$1.run(AbstractNioChannel.java:66)
...
Modification:
Make removeReadOp() read the registration field directly and null-check it before
use, mirroring the idiom already used by doBeginRead() in the same class.
Result:
removeReadOp() no longer throws when the channel has been deregistered concurrently.
Fixes netty#17103.
|
Thanks for the approval, @normanmaurer. Is anything still blocking the merge here, or is it just waiting on a batch? Happy to rebase if that would help. |
✅ All tests passed ✅🏷️ Commit: 271921f Learn more about TestLens at testlens.app. |
|
@seonwooj0810 did you sign our icla yet ? https://netty.io/s/icla |
|
@normanmaurer Yes — the ICLA for this account (seonwooj0810) has been submitted via https://netty.io/s/icla. If there is a processing delay on your end, please let me know and I can confirm the submission details. Also, thank you both to @normanmaurer and @chrisvest for the approvals on this PR! |
|
@seonwooj0810 The processing should be instant, but I don't see your github username or your email. Did the form properly submit? |
|
@seonwooj0810 please do again... it was not stored for whatever reason |
|
Thank you both for checking — sorry for the confusion. @chrisvest @normanmaurer The form did not store properly — I apologize for the failed submission. I will re-submit the ICLA at https://netty.io/s/icla immediately. Once it registers, please let me know if anything else is needed on the PR side. |
|
@seonwooj0810 I'm still not seeing it registered, but others have successfully signed in the mean time, so the form works. Maybe try a different browser, or try disabling content blockers or the like. |
|
Thank you for checking again, @chrisvest. I apologize for the repeated inconvenience. I will try the form again using a different browser as you suggested. If the submission is still not recorded after that, I will reach out separately to confirm the account details are correct. I will post an update here once the ICLA shows up on your end. |
|
Just resubmitted the ICLA form again (tried a different browser this time as suggested). Please let me know if it's still not showing up on your end. |
|
@seonwooj0810 this worked |
|
Could not create auto-port PR. |
…tration (#17104) (#17248) Fixes #17103 `clearReadPending()` guards scheduling of `clearReadPendingRunnable` with an `isRegistered()` check, which reads the `registered` boolean of `AbstractChannel`. That boolean and the `IoRegistration registration` field of `AbstractNioChannel` are not updated atomically. When a channel is deregistered from another thread *after* the `isRegistered()` check passed but *before* the runnable runs on the `EventLoop`, `doDeregister()` has already set `registration` to `null`. `removeReadOp()` then obtained the field via `registration()` (which only `assert`s non-null) and dereferenced it, producing the reported `NullPointerException` in production (or an `AssertionError` when assertions are enabled): ``` java.lang.NullPointerException at io.netty.channel.nio.AbstractNioChannel$AbstractNioUnsafe.removeReadOp(AbstractNioChannel.java:268) at io.netty.channel.nio.AbstractNioChannel.clearReadPending0(AbstractNioChannel.java:223) at io.netty.channel.nio.AbstractNioChannel$1.run(AbstractNioChannel.java:66) ... ``` Make `removeReadOp()` read the `registration` field directly and null-check it before use, mirroring the null-safe idiom already used by `doBeginRead()` in the same class. Behaviour is unchanged when the channel is still registered. `removeReadOp()` no longer throws when the channel has been deregistered concurrently. Added `AbstractNioChannelTest#testRemoveReadOpDoesNotThrowAfterDeregister`, which registers a `NioSocketChannel`, deregisters it (clearing the registration), then invokes `removeReadOp()`. The test fails on the current code (NPE / AssertionError at `AbstractNioChannel.java:264` → `registration()` at `:156`) and passes with this change. Verification done: built `transport` (+ deps) and ran the new regression test (fails before / passes after the fix); ran the existing `NioEventLoopTest` (13 tests, all green); ran the project checkstyle execution (`checkstyle:check@check-style`, no violations). Co-authored-by: Norman Maurer <[email protected]> Co-authored-by: seonwoojung <[email protected]>
Fixes #17103
Motivation
clearReadPending()guards scheduling ofclearReadPendingRunnablewith anisRegistered()check, which reads theregisteredboolean ofAbstractChannel. That boolean and theIoRegistration registrationfield ofAbstractNioChannelare not updated atomically. When a channel is deregistered from another thread after theisRegistered()check passed but before the runnable runs on theEventLoop,doDeregister()has already setregistrationtonull.removeReadOp()then obtained the field viaregistration()(which onlyasserts non-null) and dereferenced it, producing the reportedNullPointerExceptionin production (or anAssertionErrorwhen assertions are enabled):Modification
Make
removeReadOp()read theregistrationfield directly and null-check it before use, mirroring the null-safe idiom already used bydoBeginRead()in the same class. Behaviour is unchanged when the channel is still registered.Result
removeReadOp()no longer throws when the channel has been deregistered concurrently.Added
AbstractNioChannelTest#testRemoveReadOpDoesNotThrowAfterDeregister, which registers aNioSocketChannel, deregisters it (clearing the registration), then invokesremoveReadOp(). The test fails on the current code (NPE / AssertionError atAbstractNioChannel.java:264→registration()at:156) and passes with this change.Verification done: built
transport(+ deps) and ran the new regression test (fails before / passes after the fix); ran the existingNioEventLoopTest(13 tests, all green); ran the project checkstyle execution (checkstyle:check@check-style, no violations).