MiloszKrajewski / K4os.Compression.LZ4

LZ4/LH4HC compression for .NET Standard 1.6/2.0 (formerly known as lz4net)
MIT License
675 stars 77 forks source link

LZ4EncoderStream Dispose Issue #85

Closed rajeshgaddam17 closed 1 year ago

rajeshgaddam17 commented 1 year ago

Description Trying to use LZ4EncoderStream to compress and decompress but when using it we are getting below exception System.Net.Http.HttpRequestException : Error while copying content to a stream. ----> System.IO.IOException : No message provided ----> System.InvalidOperationException : Synchronous operations are disallowed. Call WriteAsync or set AllowSynchronousIO to true.

To reproduce Calling this method context.HttpContext.Response.Body.WriteAsync(byteArray, 0, byteArray.Length);

and it is using LZ4Stream.Encode(stream, null, leaveOpen: true); method to do the job but it is failing with above exception.

I have analysed the LZ4EncoderStream.cs class and it is trying to use DisposeAsync() method and inside that it is using _writer.Dispose() insteady of _writer.DisposeAsync() hence it is complaining that Synchronous operations are disallowed.

Pleas see below code

public override ValueTask DisposeAsync()
{
    _writer.Dispose();
    return base.DisposeAsync();
}

Line no 59 in LZ4EncoderStream.cs class

Expected behavior Expected compression to work when using WriteAsync() method

Actual behavior Throw below exception

System.Net.Http.HttpRequestException : Error while copying content to a stream. ----> System.IO.IOException : No message provided ----> System.InvalidOperationException : Synchronous operations are disallowed. Call WriteAsync or set AllowSynchronousIO to true.

Environment

Additional context Add any other context about the problem here.

MiloszKrajewski commented 1 year ago

Thanks for reporting. Will take a look next week.

MiloszKrajewski commented 1 year ago

I hope it has been addressed in 1.3.6, let me know.

rajeshgaddam17 commented 1 year ago

Yes, It is fixed now. Thanks for looking into it.