Skip to content

Response.json() never resolves #665

@nazar-pc

Description

@nazar-pc

I have an interesting issue with request that essentially never finishes.
It is tricky to reproduce, but everything boils down to proper timing such that there are response headers, but not response body yet.

In such circumstances I've uncovered 2 issues:

  1. Timeouts are not propagated to cloned responses, so those never time out (fixed by Propagate size and timeout to cloned response #664)
  2. Sometimes even though complete body was received (accumBytes is the same as Content-Length), body.on('end', ...) is never fired

I'm not sure how to fix the second one, one reason may be that response.size is 0 for some reason, looks like it is not read from headers or something. Hopefully maintainers can figure that out.

But at very least with mentioned PR merged it will handle timeouts on cloned response properly.

Reduced example of the code I'm dealing with is like this:

import fetch from "node-fetch";

(async () => {
    const response = await fetch(
        'http://domain.tld/path',
        {
            timeout: 2000,
        },
    );

    console.log(response.status, response.headers);
    console.log(await response.clone().json());
    console.log('This may not be printed ever, without any errors');
})();

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions