Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Fix NPE race in NettyResponseFuture.cancel (#2042)#2088

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
hyperxpro merged 2 commits intoAsyncHttpClient:mainfrompratt4:issue-2042-npe-fix
May 9, 2025

Conversation

@pratt4
Copy link
Contributor

Fixes#2042

This is a typical TOCTOU (time-of-check/time-of-use) racehttps://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.

@pratt4
Copy link
ContributorAuthor

HI@hyperxpro ...
can you please review this pr whenever you get time?

@hyperxprohyperxpro requested a review fromCopilotMay 9, 2025 17:28
Copy link
Contributor

CopilotAI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Pull Request Overview

This PR fixes a race condition that could lead to a NullPointerException when cancelling a response by copying the channel reference to a local variable.

  • Introduces a local variable "ch" to capture the channel in one atomic operation.
  • Prevents a TOCTOU race condition by ensuring the local reference remains valid during subsequent operations.

@hyperxprohyperxpro merged commit73911eb intoAsyncHttpClient:mainMay 9, 2025
3 checks passed
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

Copilot code reviewCopilotCopilot left review comments

@hyperxprohyperxprohyperxpro approved these changes

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

NPE in at org.asynchttpclient.netty.channel.Channels.setAttribute(Channels.java:36)

2 participants

@pratt4@hyperxpro

[8]ページ先頭

©2009-2025 Movatter.jp