-
Notifications
You must be signed in to change notification settings - Fork 4.9k
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
Do not drain HttpContentReadStream if the connection is disposed #57287
Do not drain HttpContentReadStream if the connection is disposed #57287
Conversation
Tagging subscribers to this area: @dotnet/ncl Issue DetailsSee #56159 (comment) for more details. Fixes #56159
|
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
@@ -46,7 +46,8 @@ protected override void Dispose(bool disposing) | |||
return; | |||
} | |||
|
|||
if (disposing && NeedsDrain) | |||
// The connection might be disposed because of cancellation. We should not drain the response in this case. | |||
if (disposing && NeedsDrain && _connection?._disposed != Status_Disposed) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If _connection is null, it will still pass this check. Is that intended?
Also, is there something somewhere that prevents this transition immediately after this check happens?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If _connection is null, it will still pass this check. Is that intended?
No, I will fix this. (Although it doesn't cause any problems since _connection == null
leads to NeedsDrain == false
.)
Also, is there something somewhere that prevents this transition immediately after this check happens?
In the race I described in #56159 (comment) connection should be always disposed at this point, or won't be disposed later. I'm not aware of other cases. @geoffkizer @ManickaP thoughts?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also, is there something somewhere that prevents this transition immediately after this check happens?
Active prevention - I don't think so. But I also don't see any such transition in the code ATM.
Would a similar check for Status_Disposed
help if it was added right before we return the connection to the pool? We're already checking for connection close there, so it might make sense...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I moved the _connection
checking to NeedsDrain
implementations in 9e8f5ba, I think the code looks more straightforward in the new form.
Regarding the second concern: if connection disposal could somehow kick in immediately after the disposal of HttpContentReadStream
that could cause a problem. I don't see how to construct such a scenario, even if it's possible, it seems corner-casish to me.
The PR fixes a serious problem with a common Send(request, HttpCompletionOption.ResponseContentRead, cancellationToken)
case as-is.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we have any stress runs from this change?
Otherwise, LGTM.
I'll approve once we have some runs and the discussion is resolved. I don't have any qualms about the change as it is now.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
I have 2 hours of local Linux runs with 0 errors (used to produce an error every 15 minutes). CI run with last changes is on the way. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have 2 hours of local Linux runs with 0 errors
Awesome! Thank you for hunting this down and fixing it!
@stephentoub pushed changes to deal with such possibility. |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
Do we have a way to write a deterministic test for this? |
/azp run runtime-libraries stress-http |
Azure Pipelines successfully started running 1 pipeline(s). |
I don't think it's possible to implement deterministic functional tests for this. What we need to validate here is that drain doesn't start in case of cancellation. We can not do this from server side since the connection is already closed when drain could possibly start. In fact, We can probably invest some time in the future to enable unit testing such behaviors though. /cc @geoffkizer |
The only CI failure is HTTP/3 stress. Merging. |
…information # By dotnet-maestro[bot] (4) and others # Via GitHub * origin/main: (58 commits) Localized file check-in by OneLocBuild Task (dotnet#57384) [debugger][wasm] Support DebuggerProxyAttribute (dotnet#56872) Account for type mismatch of `FIELD_LIST` members in LSRA (dotnet#57450) Qualify `sorted_table` allocation with `nothrow` (dotnet#57467) Rename transport packages to follow convention (dotnet#57504) Generate proper DWARF reg num for ARM32 (dotnet#57443) Enable System.Linq.Queryable and disable dotnet#50712 (dotnet#57464) Mark individual tests for 51211 (dotnet#57463) Fix Length for ReadOnlySequence created out of sliced Memory owned by MemoryManager (dotnet#57479) Add JsonConverter.Write/ReadAsPropertyName APIs (dotnet#57302) Remove workaround for dotnet/sdk#19482 (dotnet#57453) Do not drain HttpContentReadStream if the connection is disposed (dotnet#57287) [mono] Fix a few corner case overflow operations (dotnet#57407) make use of ports in SPN optional (dotnet#57159) Fixed H/3 stress server after the last Kestrel change (dotnet#57356) disable a failing stress test. (dotnet#57473) Eliminate temporary byte array allocations in the static constructor of `IPAddress`. (dotnet#57397) Update dependencies from https://github.com/dotnet/emsdk build 20210815.1 (dotnet#57447) [main] Update dependencies from mono/linker (dotnet#57344) Improve serializer performance (dotnet#57327) ... # Conflicts: # src/mono/wasm/debugger/BrowserDebugProxy/MemberReferenceResolver.cs # src/mono/wasm/debugger/BrowserDebugProxy/MonoProxy.cs # src/mono/wasm/debugger/BrowserDebugProxy/MonoSDBHelper.cs
See #56159 (comment) for more details.
Fixes #56159