Skip to content

Single-file request download reads the whole file into memory when the client stops reading #500

Closed

Description

@kikootwo

Found while fixing #490 (multi-file zip downloads, PR #498).

A request with a single file downloads it directly (GET /api/requests/[id]/download, the single-file branch in src/app/api/requests/[id]/download/route.ts). The response reads the file as fast as the disk allows and queues every chunk, whether or not the client is reading (fileStream.on('data', chunk => controller.enqueue(chunk)) never checks desiredSize).

  • A client that reads one chunk and then pauses for 3 seconds: the server has already read and queued the whole 100 MB test file.
  • So a paused or slow download of a large single-file book (for example a multi-GB m4b) holds the whole file in server memory until the client finishes or disconnects.

Multi-file zip downloads get the fix in PR #498. Single files need the same kind of change: a pull-based stream (Readable.toWeb on the file stream, or a pull() source) so the server reads only as fast as the client, and a cancel that closes the file.

Activity

  1. added a commit that references this issue on Nov 3, 2026
    11b88c4
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    ReleasedbugSomething isn't workingdev-completedev work is completed, being tested or awaiting release

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions