Skip to content
代码片段 群组 项目
未验证 提交 399ac267 编辑于 作者: BrennanConroy's avatar BrennanConroy 提交者: GitHub
浏览文件

Cancel previous request on close (#2923)

上级 753c3da8
No related branches found
No related tags found
无相关合并请求
......@@ -215,8 +215,18 @@ namespace Microsoft.AspNetCore.Http.Connections.Internal
// Cancel the previous request
connection.Cancellation?.Cancel();
// Wait for the previous request to drain
await connection.PreviousPollTask;
try
{
// Wait for the previous request to drain
await connection.PreviousPollTask;
}
catch (OperationCanceledException)
{
// Previous poll canceled due to connection closing, close this poll too
context.Response.ContentType = "text/plain";
context.Response.StatusCode = StatusCodes.Status204NoContent;
return;
}
connection.PreviousPollTask = currentRequestTcs.Task;
}
......@@ -286,6 +296,9 @@ namespace Microsoft.AspNetCore.Http.Connections.Internal
// If the status code is a 204 it means the connection is done
if (context.Response.StatusCode == StatusCodes.Status204NoContent)
{
// Cancel current request to release any waiting poll and let dispose aquire the lock
currentRequestTcs.TrySetCanceled();
// We should be able to safely dispose because there's no more data being written
// We don't need to wait for close here since we've already waited for both sides
await _manager.DisposeAndRemoveAsync(connection, closeGracefully: false);
......
0% 加载中 .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册