Skip to content

Conversation

@BrennanConroy
Copy link
Member

InMemory.FunctionalTests has crashed before due to an exception in a background task. When the InMemoryTransportConnection is closed it queues a callback to the threadpool which sets a TaskCompletionSource. If the callback is queued more than once the TCS will be set multiple times which is an error and exceptions in threadpool items will crash the process.

Simple fix is to avoid queuing the threapool item multiple times by making our closed bool set/check an atomic operation.

One test that would hit this is

public async Task ResetsCountWhenConnectionClosed()

where it would dispose the connection from test code, while in parallel the app code would start cleaning up which would call Abort.

@BrennanConroy BrennanConroy added the area-networking Includes servers, yarp, json patch, bedrock, websockets, http client factory, and http abstractions label Jan 11, 2025
@JamesNK
Copy link
Member

JamesNK commented Jan 13, 2025

Which part of the callback is crashing?

TaskCompletionSource.TrySetResult() looks safe. CancellationTokenSource.Cancel() can throw if the CTS is disposed. Does that happen here?

@BrennanConroy
Copy link
Member Author

Oh yeah, my bad. It's the CancellationTokenSource not TCS.

@BrennanConroy BrennanConroy merged commit 151d09e into main Jan 13, 2025
27 checks passed
@BrennanConroy BrennanConroy deleted the brecon/flakyclose branch January 13, 2025 03:07
@dotnet-policy-service dotnet-policy-service bot added this to the 10.0-preview1 milestone Jan 13, 2025
@danroth27 danroth27 added the task label Feb 10, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area-networking Includes servers, yarp, json patch, bedrock, websockets, http client factory, and http abstractions task

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants