Skip to content

Fetch not consuming body on error messages before launching new requests #1172

@GreenStage

Description

@GreenStage

Describe the bug
This happens to me in Cloudflare Workers

A stalled HTTP response was canceled to prevent deadlock. This can happen when a Worker calls fetch() or cache.match() several times without reading the bodies of the returned Response objects. There is a limit on the number of concurrent HTTP requests that can be in-flight at one time. Normally, additional requests made beyond that limit are delayed until previous responses complete. However, because the Worker did not read the responses, they would never complete. Therefore, to prevent deadlock, the oldest response was canceled. To avoid this warning, make sure to either read the body of every HTTP Response or call response.body.cancel() to cancel a response that you don't plan to read from.

Which looks like its cause by the worker hitting a limit of max inflight requests with pending body response streams opens.

Probably not a huge deal with other runtimes, but reading the body before disptaching other requests seem like an overall improvement so I made the issue here

To Reproduce
Steps to reproduce the behavior:

  1. Use this sdk in cloudflare workers to connect to a MCP server behind oauth.
  2. Dont give the oauth provider valid access tokens so it gets a 401 and tries to refresh tokens right away
  3. Observe all the fetch'es to oauth metadata and the authorization server endpoints and the error message above

Expected behavior
Automatic oauth flow should not result in that error message. Response body's should be (1) always consumed, and (2) read before deploying a new fetch, if possible

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions