Skip to content
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

[UNDERTOW-2403] Fix race condition in read from buffer at ServletInpu… #1602

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

fl4via
Copy link
Member

@fl4via fl4via commented Jun 13, 2024

…tStreamImpl: prevent a NPE from being thrown to invoker in case input stream is closed by another thread (which can happen typically in timeouts)

Jira: https://issues.redhat.com/browse/UNDERTOW-2403

…tStreamImpl: prevent a NPE from being thrown to invoker in case input stream is closed by another thread (which can happen typically in timeouts)

Signed-off-by: Flavia Rainone <[email protected]>
@fl4via fl4via added the bug fix Contains bug fix(es) label Jun 13, 2024
@fl4via fl4via requested review from baranowb and ropalka June 13, 2024 17:51
}
}
}
}

private void closePoolIfNotNull() {
try {
if (pooled != null) {
Copy link
Contributor

Choose a reason for hiding this comment

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

ONly thing Id consider is to have local var? unless thats calculated choice to sometimes pay price of exception, rather than constant cost of local var and assignment.

Copy link
Contributor

Choose a reason for hiding this comment

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

@fl4via ^^

Copy link
Member Author

@fl4via fl4via Jun 20, 2024

Choose a reason for hiding this comment

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

We will pay the price of the NPE anyway, but, yes, I think adding the local var is a good idea because it will make the exception less likely.

if (pooled != null) {
   final PooledByteBuffer pooled = this.pooled; // we can still read a null value here, hence, NPE when closing
   this.pooled = null;
   pooled.close();  // marginal risk of NPE here
} 

Copy link
Member Author

Choose a reason for hiding this comment

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

As a secod thought, will it make it less likely, if the time spent seting it to a variable might be the same time it takes to invoke close directly? Or is it not? I'll try to see if I can find some information on this. But the code I suggested above might have the same statistical risk of getting the NPE as the one we have without the local variable.

@baranowb baranowb added waiting PR update Awaiting PR update(s) from contributor before merging failed CI Introduced new regession(s) during CI check labels Jun 24, 2024
@baranowb
Copy link
Contributor

Im going to trigger CI once more. Most likely this either needs to disable on mac or expect failure. Most likely we should have some sort of OS specific annotations or utility to make this kind of exclusion easier.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug fix Contains bug fix(es) failed CI Introduced new regession(s) during CI check waiting PR update Awaiting PR update(s) from contributor before merging
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants