Skip to content

Asynchronous ZipArchive stream methods still call synchronous methods of the underlying stream #107171

Closed

Description

@serggusak

Description

Asynchronous ZipArchive stream methods still call synchronous methods of the underlying stream:

using (var zip = new ZipArchive(/new WriteOnlyStreamWrapper(/httpContext.Response.Body/)/, ZipArchiveMode.Create))
await using (Stream strm = zip.CreateEntry("response").Open())
{
await strm.WriteAsync(bytes); // Synchronous operations are disallowed exception here
}

If I debug using my wrapper, I can see that Flush is called on the stream instead of FlushAsync

Reproduction Steps

Write some code that creates a ZipArchive for writing around a stream that supports only asynchronous operations, creates an entry, open it and write some data to the stream asynchronously.

Expected behavior

The data has been successfully written

Actual behavior

Get "Synchronous operations are disallowed" exception because the framework calls a synchronous method (Flush)

Regression?

No response

Known Workarounds

No response

Configuration

.Net 8, Windows, x64

Other information

No response

Activity

  1. added
    untriaged
    on Aug 30, 2024
  2. dotnet-policy-service commented on Aug 30, 2024

    @dotnet-policy-service
    Contributor

    Tagging subscribers to this area: @dotnet/area-system-io-compression
    See info in area-owners.md if you want to be subscribed.

  3. added
    needs-further-triage
    and removed
    untriaged
    on Sep 4, 2024
  4. added this to the Future milestone on Sep 4, 2024
  5. ericstj commented on Sep 4, 2024

    @ericstj
    Member

    Triage: not a regression - could be considered for the future with a proposed design change.

  6. carlossanlop commented on Apr 17, 2025

    @carlossanlop
    Contributor

    This should've been fixed with the introduction of the new async APIs: #114421

    I added tests to confirm that no zip async APIs are calling stream sync APIs, and no zip sync APIs are calling stream async APIs.

    @serggusak do you have a chance to test the new APIs?

  7. removed
    needs-further-triage
    on Apr 17, 2025
  8. self-assigned this
    on Apr 17, 2025
  9. carlossanlop commented on Apr 22, 2025

    @carlossanlop
    Contributor

    This should be fixed now. If anyone finds problems, please open a new issue.

  10. locked and limited conversation to collaborators on May 23, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions