diff --git a/src/Servers/Kestrel/Core/src/Internal/Http/Http1OutputProducer.cs b/src/Servers/Kestrel/Core/src/Internal/Http/Http1OutputProducer.cs
index 374abf7adf..b3c0248838 100644
--- a/src/Servers/Kestrel/Core/src/Internal/Http/Http1OutputProducer.cs
+++ b/src/Servers/Kestrel/Core/src/Internal/Http/Http1OutputProducer.cs
@@ -722,10 +722,16 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http
{
if (_writeStreamSuffixCalled)
{
- throw new InvalidOperationException("Writing is not allowed after writer was completed.");
+ ThrowSuffixSent();
}
}
+ [StackTraceHidden]
+ private static void ThrowSuffixSent()
+ {
+ throw new InvalidOperationException("Writing is not allowed after writer was completed.");
+ }
+
///
/// Holds a byte[] from the pool and a size value. Basically a Memory but guaranteed to be backed by an ArrayPool byte[], so that we know we can return it.
///
diff --git a/src/Servers/Kestrel/Core/src/Internal/Http/HttpProtocol.cs b/src/Servers/Kestrel/Core/src/Internal/Http/HttpProtocol.cs
index 3f879207f2..6caeb980c8 100644
--- a/src/Servers/Kestrel/Core/src/Internal/Http/HttpProtocol.cs
+++ b/src/Servers/Kestrel/Core/src/Internal/Http/HttpProtocol.cs
@@ -1442,7 +1442,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http
// so it can be observed by BodyWriter.Complete(). If this isn't possible because an
// async OnStarting callback hadn't yet run, it's OK, since the Exception will be observed with
// the call to _bodyControl.StopAsync() in ProcessRequests().
- throw lengthException;
+ ThrowException(lengthException);
}
return ProduceEnd();
@@ -1459,13 +1459,19 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http
{
if (!VerifyResponseContentLength(out var lengthException))
{
- throw lengthException;
+ ThrowException(lengthException);
}
await ProduceEnd();
}
}
+ [StackTraceHidden]
+ private static void ThrowException(Exception exception)
+ {
+ throw exception;
+ }
+
public ValueTask WritePipeAsync(ReadOnlyMemory data, CancellationToken cancellationToken)
{
// For the first write, ensure headers are flushed if WriteDataAsync isn't called.
diff --git a/src/Servers/Kestrel/Core/src/Internal/Http2/Http2OutputProducer.cs b/src/Servers/Kestrel/Core/src/Internal/Http2/Http2OutputProducer.cs
index 6726f1fed6..6d08b0555d 100644
--- a/src/Servers/Kestrel/Core/src/Internal/Http2/Http2OutputProducer.cs
+++ b/src/Servers/Kestrel/Core/src/Internal/Http2/Http2OutputProducer.cs
@@ -437,10 +437,16 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http2
{
if (_suffixSent)
{
- throw new InvalidOperationException("Writing is not allowed after writer was completed.");
+ ThrowSuffixSent();
}
}
+ [StackTraceHidden]
+ private static void ThrowSuffixSent()
+ {
+ throw new InvalidOperationException("Writing is not allowed after writer was completed.");
+ }
+
private static Pipe CreateDataPipe(MemoryPool pool)
=> new Pipe(new PipeOptions
(