-
Notifications
You must be signed in to change notification settings - Fork 10.5k

Description
Describe the bug
Under extreme load, we have noticed that the PipeWriter.GetMemory() method will fail with an InvalidOperationException of "Writing is not allowed after writer was completed."
To Reproduce
We are processing ~4,000-6,000 requests/second over a TCP connection, for which I have written a custom ConnectionHandler. The request sizes vary from ~150 bytes to ~100k, but can be replicated with the smaller request size. For reference, the response is ~3-5 times that of the request. This issue only started to show up after we were able to run performance tests near the server's maximum capacity.
At first I thought that it was just a closed connection, but these exceptions are occurring while the CancellationToken of ConnectionContext.ConnectionClosed has an IsCancellationRequested property value of false. It is possible that the connection is closed, but this property is not showing it as such. Due to the way that the loss of a connection works, it creates a race condition and we have not had any success at reproducing the issue in a debug session.
Exceptions (if any)
InvalidOperationException: Writing is not allowed after writer was completed.
Further technical details
- ASP.NET Core version: 3.1.301
- This is running on AWS Linux, latest release, netcoreapp3.1, Self-Contained, linux-x64