Skip to content

Exception when used locally in 4.0.0. Kestrel related? #401

@marklagendijk

Description

@marklagendijk

Prerequisites

  • I have written a descriptive issue title
  • I have verified that I am running the latest version of ImageSharp.Web
  • I have verified if the problem exist in both DEBUG and RELEASE mode
  • I have searched open and closed issues to ensure it has not already been reported

ImageSharp.Web version

4.0.0

Other Six Labors packages and versions

ImageSharp 4.0.0

Environment (Operating system, version and so on)

Windows 11, Kestrel

.NET version

10.0

Description

Since 4.0.0, when running ImageSharp.Web locally or in the CI/CD pipelines the following exception is thrown intermittently. On our production system (Azure App Service, Windows) it is not thrown at all.

fail: Microsoft.AspNetCore.Server.Kestrel[13]
      Connection id "0HNM646UV6KOA", Request id "0HNM646UV6KOA:00000017": An unhandled exception was thrown by the application.
      System.ArgumentException: An item with the same key has already been added. Key: autoorient
         at System.Collections.Generic.Dictionary`2.TryInsert(TKey key, TValue value, InsertionBehavior behavior)
         at System.Collections.Generic.Dictionary`2.Add(TKey key, TValue value)
         at System.Collections.ObjectModel.KeyedCollection`2.AddKey(TKey key, TItem item)
         at System.Collections.ObjectModel.KeyedCollection`2.InsertItem(Int32 index, TItem item)
         at System.Collections.ObjectModel.Collection`1.Insert(Int32 index, T item)
         at SixLabors.ImageSharp.Web.Middleware.ImageSharpMiddlewareOptions.<>c.<.ctor>b__56_1(ImageCommandContext context)
         at SixLabors.ImageSharp.Web.Middleware.ImageSharpMiddleware.Invoke(HttpContext httpContext, Boolean retry)
         at Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http.HttpProtocol.ProcessRequests[TContext](IHttpApplication`1 application)

Based on the stacktrace, it seems like the following line is causing the issue:

context.Commands.Insert(0, new KeyValuePair<string, string?>(AutoOrientWebProcessor.AutoOrient, bool.TrueString));

I have no clue why, could it be a concurrency issue?

Steps to Reproduce

Unknown at this point.

Images

Not applicable.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions