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

Ensure FileBufferingReadStream created by formatters are always disposed (#22746)

上级 5a9a9854
No related branches found
No related tags found
无相关合并请求
...@@ -143,6 +143,8 @@ namespace Microsoft.AspNetCore.Mvc.Formatters ...@@ -143,6 +143,8 @@ namespace Microsoft.AspNetCore.Mvc.Formatters
} }
readStream = new FileBufferingReadStream(request.Body, memoryThreshold); readStream = new FileBufferingReadStream(request.Body, memoryThreshold);
// Ensure the file buffer stream is always disposed at the end of a request.
request.HttpContext.Response.RegisterForDispose(readStream);
await readStream.DrainAsync(CancellationToken.None); await readStream.DrainAsync(CancellationToken.None);
readStream.Seek(0L, SeekOrigin.Begin); readStream.Seek(0L, SeekOrigin.Begin);
......
...@@ -124,6 +124,8 @@ namespace Microsoft.AspNetCore.Mvc.Formatters ...@@ -124,6 +124,8 @@ namespace Microsoft.AspNetCore.Mvc.Formatters
} }
readStream = new FileBufferingReadStream(request.Body, memoryThreshold); readStream = new FileBufferingReadStream(request.Body, memoryThreshold);
// Ensure the file buffer stream is always disposed at the end of a request.
request.HttpContext.Response.RegisterForDispose(readStream);
await readStream.DrainAsync(CancellationToken.None); await readStream.DrainAsync(CancellationToken.None);
readStream.Seek(0L, SeekOrigin.Begin); readStream.Seek(0L, SeekOrigin.Begin);
......
...@@ -153,6 +153,8 @@ namespace Microsoft.AspNetCore.Mvc.Formatters ...@@ -153,6 +153,8 @@ namespace Microsoft.AspNetCore.Mvc.Formatters
} }
readStream = new FileBufferingReadStream(request.Body, memoryThreshold); readStream = new FileBufferingReadStream(request.Body, memoryThreshold);
// Ensure the file buffer stream is always disposed at the end of a request.
request.HttpContext.Response.RegisterForDispose(readStream);
await readStream.DrainAsync(CancellationToken.None); await readStream.DrainAsync(CancellationToken.None);
readStream.Seek(0L, SeekOrigin.Begin); readStream.Seek(0L, SeekOrigin.Begin);
...@@ -278,7 +280,7 @@ namespace Microsoft.AspNetCore.Mvc.Formatters ...@@ -278,7 +280,7 @@ namespace Microsoft.AspNetCore.Mvc.Formatters
/// <summary> /// <summary>
/// Called during deserialization to get the <see cref="JsonSerializer"/>. The formatter context /// Called during deserialization to get the <see cref="JsonSerializer"/>. The formatter context
/// that is passed gives an ability to create serializer specific to the context. /// that is passed gives an ability to create serializer specific to the context.
/// </summary> /// </summary>
/// <returns>The <see cref="JsonSerializer"/> used during deserialization.</returns> /// <returns>The <see cref="JsonSerializer"/> used during deserialization.</returns>
/// <remarks> /// <remarks>
...@@ -297,7 +299,7 @@ namespace Microsoft.AspNetCore.Mvc.Formatters ...@@ -297,7 +299,7 @@ namespace Microsoft.AspNetCore.Mvc.Formatters
/// <summary> /// <summary>
/// Called during deserialization to get the <see cref="JsonSerializer"/>. The formatter context /// Called during deserialization to get the <see cref="JsonSerializer"/>. The formatter context
/// that is passed gives an ability to create serializer specific to the context. /// that is passed gives an ability to create serializer specific to the context.
/// </summary> /// </summary>
/// <param name="context">A context object used by an input formatter for deserializing the request body into an object.</param> /// <param name="context">A context object used by an input formatter for deserializing the request body into an object.</param>
/// <returns>The <see cref="JsonSerializer"/> used during deserialization.</returns> /// <returns>The <see cref="JsonSerializer"/> used during deserialization.</returns>
......
0% 加载中 .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册