-
Notifications
You must be signed in to change notification settings - Fork 10.5k
Description
Today Kestrel will close an HTTP/2 connection if it receives headers over the specified total size limit MaxRequestHeadersTotalSize (32kb default).
[0.010s] [Microsoft.AspNetCore.Server.Kestrel] [Debug] Connection id "0HLRVURJ3P9V8": HTTP/2 connection error.
Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http2.Http2ConnectionErrorException: HTTP/2 connection error (PROTOCOL_ERROR): Request headers too long.
at Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http2.Http2Connection.OnHeader(ReadOnlySpan`1 name, ReadOnlySpan`1 value) in D:\github\AspNetCore\src\Servers\Kestrel\Core\src\Internal\Http2\Http2Connection.cs:line 1084
at System.Net.Http.HPack.HPackDecoder.ProcessHeaderValue(IHttpHeadersHandler handler) in D:\github\AspNetCore\src\Shared\Http2\Hpack\HPackDecoder.cs:line 380
at System.Net.Http.HPack.HPackDecoder.DecodeInternal(ReadOnlySpan`1 data, Boolean endHeaders, IHttpHeadersHandler handler) in D:\github\AspNetCore\src\Shared\Http2\Hpack\HPackDecoder.cs:line 340
at System.Net.Http.HPack.HPackDecoder.Decode(ReadOnlySequence`1& data, Boolean endHeaders, IHttpHeadersHandler handler) in D:\github\AspNetCore\src\Shared\Http2\Hpack\HPackDecoder.cs:line 126
at Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http2.Http2Connection.DecodeHeadersAsync(Boolean endHeaders, ReadOnlySequence`1& payload) in D:\github\AspNetCore\src\Servers\Kestrel\Core\src\Internal\Http2\Http2Connection.cs:line 865
at Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http2.Http2Connection.ProcessContinuationFrameAsync(ReadOnlySequence`1& payload) in D:\github\AspNetCore\src\Servers\Kestrel\Core\src\Internal\Http2\Http2Connection.cs:line 846
at Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http2.Http2Connection.ProcessFrameAsync[TContext](IHttpApplication`1 application, ReadOnlySequence`1& payload) in D:\github\AspNetCore\src\Servers\Kestrel\Core\src\Internal\Http2\Http2Connection.cs:line 404
at Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http2.Http2Connection.ProcessRequestsAsync[TContext](IHttpApplication`1 application) in D:\github\AspNetCore\src\Servers\Kestrel\Core\src\Internal\Http2\Http2Connection.cs:line 208
The HTTP/2 RFC recommends sending a 431 response instead. That would be consistent with our HTTP/1.1 code path, and it would avoid failing all of the other active requests on a connection.
https://tools.ietf.org/html/rfc7540#section-10.5.1
A server that receives a larger header block than it is willing to
handle can send an HTTP 431 (Request Header Fields Too Large) status
code [RFC6585]. A client can discard responses that it cannot
process. The header block MUST be processed to ensure a consistent
connection state, unless the connection is closed.
Since we're required to continue HPACK processing the headers in order to keep the connection alive and send a 431 response, there may be some practical limit before we decide to close the connection instead. E.g. 2x MaxRequestHeadersTotalSize.