question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

clone() hangs with large response in Node

See original GitHub issue

Issuehunt badges

I hit this bug today, it was caused by https://github.com/bitinn/node-fetch/issues/386

The bug makes ky-universal not useable at all in node. (You don’t know when the code will hang as you don’t know the response size ahead of time)

Is there a way to remove clone() from the source code?


IssueHunt Summary

xxczaki xxczaki has been rewarded.

Backers (Total: $80.00)

Submitted pull Requests


Tips

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:2
  • Comments:8 (2 by maintainers)

github_iconTop GitHub Comments

4reactions
xxczakicommented, Sep 24, 2019

@gutenye @sindresorhus In version 3.0.0 of node-fetch you will be able to manually set highWaterMark and prevent this issue from happening 😄

fetch(url, {highWaterMark: 10}).then(res => res.clone().buffer());

See this PR

3reactions
sholladaycommented, Jul 9, 2019

It would be pretty challenging to re-implement .clone() ourselves. In doing so, we would probably end up creating more new bugs than we solved. The only practical way forward that I see here would be to just not clone the response at all.

We currently clone in three places:

  1. When calling afterResponse hooks
  2. When streaming the response to provide progress events
  3. When body method shortcuts are used (e.g. ky().json())

I’m not sure which, if any, of these places would be safe to remove. None of them seem particularly important to me, though I like having them for safety.

It’s worth noting that we only call .clone() if you use one of the above mentioned features. So you can actually avoid this problem if you can live without those features.

For example, if .clone() is being called because you are using the .json() method like this:

const users = await ky.get('users').json();

It’s perfectly fine to re-write that to:

const response = await ky.get('users');
const users = await response.json();

… in which case .clone() is not called. The only caveat, beyond it being more verbose, is that you will also have to set the Accept: application/json header yourself, if you need that.

Other than those workarounds, I’m not sure there’s much we can do, since we are using the API correctly and this is really an upstream issue. We could explore alternative fetch polyfills, but I suspect that would again introduce its own set of problems. Let’s keep an eye on that issue you referenced.

In the meantime, should we consider removing .clone() internally and, if so, where? Removing 3 seems the safest to me and it’s probably the most common case as well.

Read more comments on GitHub >

github_iconTop Results From Across the Web

node.js http.get hangs after 5 requests to remote site
In your code, you don't consume the actual response sent by Google. So the agent assumes that you're not done with the request,...
Read more >
Top 10 Most Common Node.js Developer Mistakes - Toptal
Invoking this “sortUsersByAge” function may be fine if run on a small “users” array, but with a large array, it will have a...
Read more >
Troubleshooting queries - Amazon Redshift
Your client connection to the database appears to hang or time out when running long queries, such as a COPY command. In this...
Read more >
15 Common Error Codes in Node.js and How to Fix Them
ECONNRESET. ECONNRESET is a common exception that occurs when the TCP connection to another server is closed abruptly, usually before a response ......
Read more >
This is why your Node.js application is slow
/* Sample promises to simulate asynchronous operation. * Let's assume these are sample DB operations and their equivalent response time. *. */.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found