-
Notifications
You must be signed in to change notification settings - Fork 1.6k
NPE in at org.asynchttpclient.netty.channel.Channels.setAttribute(Channels.java:36) #2042
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
Comments
I noticed that in the |
This is likely a race condition. Do you plan for a PR? |
yes,I will handle it in the next two days and provide a PR. |
Hi, I’d like to work on this |
Sure, please send a PR. |
Hi, I have opened a PR, please review |
Fixes #2042 This is a typical TOCTOU (time-of-check/time-of-use) race https://en.wikipedia.org/wiki/Time-of-check_to_time-of-use. The NPE was occurring because the channel field could be set to null by another thread between the check and its use: if (channel != null) { // time-of-check Channels.setDiscard(channel); // time-of-use Channels.silentlyCloseChannel(channel); } By copying channel into a local variable in one atomic read, we ensure that—even if another thread changes the field—the local reference remains valid. P.S. It is hard to write a deterministic test that fails consistently, so this PR only includes the code fix. --------- Co-authored-by: prat <[email protected]>
java.lang.NullPointerException
at org.asynchttpclient.netty.channel.Channels.setAttribute(Channels.java:36)
at org.asynchttpclient.netty.channel.Channels.setDiscard(Channels.java:40)
at org.asynchttpclient.netty.NettyResponseFuture.cancel(NettyResponseFuture.java:183)
The text was updated successfully, but these errors were encountered: