Skip to content

fetch() resolves when its request body stream yields a non-byte chunk, cutting the body short #8078

Open

Description

@jasnell

Follow-up from review of #8053 (#8053 (review)).

If a JS-sourced ReadableStream used as a fetch() request body enqueues a chunk that is neither bytes nor a string (e.g. a number), the body pump fails, but fetch() still resolves. The request goes out with its body cut short, and the error only shows up as an uncaught exception from the pump's waitUntil task (and, for a pull source, in the source's cancel()).

Both implementations behave this way. Only the error text differs:

  • C++: TypeError: Draining read encountered a value that cannot be converted to bytes
  • TS (typescript_implemented_streams): TypeError: This ReadableStream did not return bytes.

The pump runs apart from the response (handleCancelablePump in http.c++), so its failure never reaches the fetch() promise.

We likely won't change the C++ side. We may revisit the TS-streams behavior, e.g. to surface the failure more usefully.

Activity

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