diff --git a/src/Servers/IIS/IIS/test/testassets/InProcessWebSite/Startup.WebSockets.cs b/src/Servers/IIS/IIS/test/testassets/InProcessWebSite/Startup.WebSockets.cs index d0750ef81fd4..fda6e51107c4 100644 --- a/src/Servers/IIS/IIS/test/testassets/InProcessWebSite/Startup.WebSockets.cs +++ b/src/Servers/IIS/IIS/test/testassets/InProcessWebSite/Startup.WebSockets.cs @@ -120,7 +120,13 @@ private static async Task Upgrade(HttpContext context) // Upgrade the connection Stream opaqueTransport = await upgradeFeature.UpgradeAsync(); - Assert.Null(context.Features.Get().MaxRequestBodySize); + + // In-process reads upgraded data through the same loop that enforces MaxRequestBodySize, so it + // must clear the limit. Out-of-process runs on Kestrel, which never enforces it once upgraded. + if (context.Features.Get() is not null) + { + Assert.Null(context.Features.Get().MaxRequestBodySize); + } // Get the WebSocket object var ws = WebSocket.CreateFromStream(opaqueTransport, isServer: true, subProtocol: null, keepAliveInterval: TimeSpan.FromMinutes(2));