-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit 73911eb
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 <pratikkatti4@gmial.com>
1 parent 14ee30a commit 73911eb
File tree
1 file changed
+4
-4
lines changed- client/src/main/java/org/asynchttpclient/netty
1 file changed
+4
-4
lines changedLines changed: 4 additions & 4 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
187 | 187 | | |
188 | 188 | | |
189 | 189 | | |
190 | - | ||
191 | - | ||
192 | - | ||
193 | - | ||
190 | + | ||
191 | + | ||
192 | + | ||
193 | + | ||
194 | 194 | | |
195 | 195 | | |
196 | 196 | | |
| |||
0 commit comments