Skip to content

Fallback for older node versions doesn't accept backpressure from readable stream #349

Closed

Description

@Arlen22

I don't actually know if readable streams support backpressure in this way, but the incoming data stream is not paused and resumed to allow backpressure. According to google, Readable.toWeb applies backpressure properly, so this only applies to the fallback. This would result in older versions reading the entire file into memory quickly and then slowly trickling it out over TCP.

const createStreamBody = (stream) => {
	if (useReadableToWeb) return Readable.toWeb(stream);
	return new ReadableStream({
		start(controller) {
			stream.on("data", (chunk) => {
				controller.enqueue(chunk);
			});
			stream.on("error", (err) => {
				controller.error(err);
			});
			stream.on("end", () => {
				controller.close();
			});
		},
		cancel() {
			stream.destroy();
		}
	});
};

Activity

  1. usualoma commented on May 7, 2026

    @usualoma
    Member

    Hi @Arlen22,
    Thanks for pointing this out.

    You’re right that the current fallback can use more memory when serving large files to slow clients. If we were to address it, the change would look something like this:

    #351

    That said, Node.js 20.x is already EOL, and Node.js 22.x avoids this fallback path when using a recent minor version. So I’m still not sure whether it is worth adding this complexity.

  2. usualoma commented on May 7, 2026

    @usualoma
    Member

    Hi @yusukebe,
    What do you think?

  3. yusukebe commented on May 7, 2026

    @yusukebe
    Member

    Hi @usualoma

    I see! As you said, Node.js 20.x is EOL, and we may not need to be eager to support it, but actually, this adapter says "It works on Node.js versions greater than 20.x." on the README. So it's better to apply the PR #351. It already seems good and not too large.

  4. added a commit that references this issue on May 13, 2026
    1a9748e
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

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions