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

StreamPipeReader NullReferenceException in some multithreading scenarios #101893

Open
JamesNK opened this issue May 5, 2024 · 1 comment
Open
Labels
area-System.IO.Pipelines untriaged New issue has not been triaged by the area owner

Comments

@JamesNK
Copy link
Member

JamesNK commented May 5, 2024

Description

NullReferenceException has been observed from StreamPipeReader. Likely caused by misuse (multiple concurrent calls to ReadAsync), however a more useful error should be thrown than NRE.


From investigation:

There is a nullref if the internal Stream.ReadAsync call returns and StreamPipeReader is adding a new BufferSegment while at the same time the reader is being completed and unsets BufferSegment state.

The specific lines are BufferSegment.cs where segment.NextSegment can be null if BufferSegment.cs sets _next to null right after the while check in SetNext.

Another bug in the same scenario is an ArgumentOutOfRange exception when incrementing the End value at StreamPipeReader.cs which calls Slice on the AvailableMemory which is now empty from the Complete call.

Reproduction Steps

Possibly caused by multiple concurrent ReadAsync calls.

Expected behavior

More informative error. Or no error. Should look at what other pipe readers do in this situation.

Actual behavior

NullReferenceException thrown.

Regression?

No

Known Workarounds

No response

Configuration

.NET 8

Other information

No response

@dotnet-policy-service dotnet-policy-service bot added the untriaged New issue has not been triaged by the area owner label May 5, 2024
@JamesNK
Copy link
Member Author

JamesNK commented May 5, 2024

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-System.IO.Pipelines untriaged New issue has not been triaged by the area owner
Projects
None yet
Development

No branches or pull requests

1 participant