Skip to content

Decompression middle-ware does not guarantee decompression all the time #64697

@okarpov

Description

@okarpov

Is there an existing issue for this?

  • I have searched the existing issues

Describe the bug

Having he following pipeline/structure does not guarantee decompression all the time.


public static void Main(string[] args)
{
    var builder = WebApplication.CreateBuilder(args);

    builder.WebHost.ConfigureKestrel(options =>
    {
        options.Limits.MaxConcurrentConnections = null; //null = max
        options.Limits.MaxRequestBodySize = 30_000_000; // default
        options.Limits.Http2.MaxStreamsPerConnection = 1000; // default is 100
    });

    builder.Services.Configure<WorkerOptions>(builder.Configuration.GetSection("WorkerOptions"));
    builder.Services.AddHostedService<MyBackgroundService>();

    builder.Services.AddRequestDecompression(); // №1
    builder.Services.AddResponseCompression(); // №2


    var app = builder.Build();

    app.UseHttpsRedirection();

    app.UseRequestDecompression(); // №3
    app.UseResponseCompression(); // №4
    ...
    app.MapPost("/setstatus", async (HttpContext httpContext) =>
    {
        using StreamReader sr = new StreamReader(httpContext.Request.Body);
        string b64Utf8 = await sr.ReadToEndAsync().ConfigureAwait(false);

        b64Utf8 = b64Utf8.Trim('"');

        string json = Encoding.UTF8.GetString(Convert.FromBase64String(b64Utf8));
        ...
    }
}


when i'm restarting this webapp while other clients are still sending requests to this webapp i see a few 'System.FormatException: The input is not a valid Base-64 string as it contains a non-base 64 character ...' exceptions and when i look into the b64Utf8 i see something like:

� �0 E��?h� �Th a����c0�D� _o1n�ݜ;��n

Expected Behavior

supposed to decompress 100% requests unless №1 and №2 (and probably №3 and №4) suppposed to be the very first two lines of each pipeline

Steps To Reproduce

  1. run web app
  2. start sending https requests to it
  3. restart web app while requests are being sent
  4. a few requests throw the exception on start

Exceptions (if any)

System.FormatException: The input is not a valid Base-64 string as it contains a non-base 64 character

.NET Version

8.0.416

Anything else?

even more, if i read body as bytes and decompress with GZipStream inside of catch-block on such exception then i get correct base64 with no error/exception.

Metadata

Metadata

Assignees

No one assigned

    Labels

    area-networkingIncludes servers, yarp, json patch, bedrock, websockets, http client factory, and http abstractions

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions