dotnet / aspnetcore

ASP.NET Core is a cross-platform .NET framework for building modern cloud-based web applications on Windows, Mac, or Linux.
https://asp.net
MIT License
35.59k stars 10.06k forks source link

IndexOutOfRangeException in Microsoft.AspNetCore.Server.IIS.Core.IISHttpContext.ExtraFeatureSet #56762

Open zlatanov opened 4 months ago

zlatanov commented 4 months ago

Is there an existing issue for this?

Describe the bug

Sometimes we get the following error logged:

IndexOutOfRangeException: Index was outside the bounds of the array.
    at Microsoft.AspNetCore.Server.IIS.Core.IISHttpContext.ExtraFeatureSet(Type key, Object value)
    at Microsoft.AspNetCore.ResponseCompression.ResponseCompressionMiddleware.InvokeCore(HttpContext context)

Looking at the code there, I can't find anything that would cause this error if the code there is not accessed concurrently. Is it possible that, if a connection is aborted while for example the ResponseCompressionMiddleware is being executed, that this ExtraFeatureSet might get executed concurrently?

Expected Behavior

No exception to occur.

Steps To Reproduce

No response

Exceptions (if any)

No response

.NET Version

8.0.2

Anything else?

No response

gfoidl commented 4 months ago

Out of curiosity: can you reproduce the same error when using Kestrel instead of IIS? (because the code for ExtraFeatureSet is the same)

zlatanov commented 4 months ago

Out of curiosity: can you reproduce the same error when using Kestrel instead of IIS? (because the code for ExtraFeatureSet is the same)

No, the error happens very rarely and only in production.