Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix(premature close) Redirect failing when response is chunked but empty #1222

Conversation

tekwiz
Copy link
Member

@tekwiz tekwiz commented Jul 26, 2021

What is the purpose of this pull request?

  • Documentation update
  • Bug fix
  • New feature
  • Other, please explain:

What changes did you make? (provide an overview)

When an abort signal is given, the test for a properly closed chunked request should be skipped.

Which issue (if any) does this pull request address?

Is there anything you'd like reviewers to know?

@tekwiz tekwiz force-pushed the fix/redirect-with-empty-chunked-transfer-encoding branch from 186138a to 86d3005 Compare July 26, 2021 19:06
@jimmywarting
Copy link
Collaborator

Going to take a look at this tomorrow.

Just so I know, is #1064 and this PR just a fix to handle a older node:stream that dose things incorrectly?
I did see some if node < x then do this logic...
If we where to drop support for NodeJS version older than 14.13.1 would this still be relevant?

@tekwiz
Copy link
Member Author

tekwiz commented Jul 27, 2021

@jimmywarting #1064 is actually 2 fixes related to premature close problems. The first part is to handle the bad ending of chunked transfers, which is applicable to to all Node.js 10-14 (and I haven't tested 16). The second part is to fix the async iterator issue with Node.js 12. I will update #1064 to clarify.

@jimmywarting
Copy link
Collaborator

The second part is to fix the async iterator issue with Node.js 12

The reason why i asked was that it could be nice to remove the async iterator hack/fix if we decide to remove support for node < 14 sometime later, but i guess NodeJS will have added fetch into core at that point

@tekwiz
Copy link
Member Author

tekwiz commented Jul 27, 2021

The second part is to fix the async iterator issue with Node.js 12

The reason why i asked was that it could be nice to remove the async iterator hack/fix if we decide to remove support for node < 14 sometime later, but i guess NodeJS will have added fetch into core at that point

Yes, we can definitely remove the async iterator hack/fix next year when Node.js 12 goes EOL (https://github.com/nodejs/Release)

Copy link
Collaborator

@jimmywarting jimmywarting left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I downloaded your patch and tried both

fetch('https://blog.logrocket.com/feed')
  .then(r => r.arrayBuffer())
  .then(console.log) 
  // works in browser, Throws in node-fetch with Invalid response body while
  // trying to fetch https://fex.baidu.com/feed.xml: Premature close
fetch('https://fex.baidu.com/feed.xml')
  .then(r => r.arrayBuffer())
  .then(console.log) // works in browser, and also this PR

…parate packets and where there is an additional data chunk in the same packet before the final chunk and EOM code.
@tekwiz tekwiz force-pushed the fix/redirect-with-empty-chunked-transfer-encoding branch from 925cb21 to d19fdac Compare July 28, 2021 01:18
@tekwiz
Copy link
Member Author

tekwiz commented Jul 28, 2021

@jimmywarting Found the issues. Please give this fix a try.

@tekwiz tekwiz requested a review from jimmywarting July 28, 2021 01:22
@jimmywarting jimmywarting mentioned this pull request Jul 28, 2021
@jimmywarting jimmywarting marked this pull request as draft July 28, 2021 09:29
@jimmywarting
Copy link
Collaborator

jimmywarting commented Jul 28, 2021

@jimmywarting Found the issues. Please give this fix a try.

tested, works fine now on nodejs v16.5

I'll do some more testing today.
Originally posted by @tekwiz in #1219 (comment)

Marking as draft then, mark as ready to review when you are done

@jimmywarting
Copy link
Collaborator

@tekwiz have you run some tests?

@tekwiz tekwiz marked this pull request as ready for review July 30, 2021 21:00
@tekwiz
Copy link
Member Author

tekwiz commented Jul 30, 2021

@tekwiz have you run some tests?

Yes, apologies for the delay. The day job got in the way. It turns out the Node.js 16 does a better job of handling bad endings of chunked encodings -- it throws an Error with the simple message "aborted" instead of hanging or timing out. However, with the nonspecific-ness of that error and for the sake of consistency, my opinion is to leave the fixResponseChunkedTransferBadEnding check in place for Node.js 16.

@AlenToma
Copy link

Tiered of waiting, When will this get checked in and build an npm

@jimmywarting
Copy link
Collaborator

Need at least 2 approvals for it to get merged

Copy link
Member

@LinusU LinusU left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice 👍

@AlenToma
Copy link

Yes at last now, will be greet to check #1237

@jimmywarting jimmywarting added this to the Version 3.0.0 milestone Aug 12, 2021
@jimmywarting jimmywarting changed the title Fix redirect failing when response is chunked but empty. #1220 #1064 Fix(premature close) Redirect failing when response is chunked but empty Aug 12, 2021
@jimmywarting jimmywarting merged commit 51861e9 into node-fetch:main Aug 12, 2021
@jimmywarting
Copy link
Collaborator

jimmywarting commented Aug 12, 2021

Thinking we will skip a beta.11 with this pr (fix) and just publish v3.0.0 (stable) instead
The only beef we have tackle now is regarding ESM vs CJS (#1236)
There isn't really any other huge blockers that would bring any more breaking changes to the core (other than the ESM vs CJS discussion we have). The rest can be handled with minor or patch versions.

I thought this PR was needed cuz it broke something that used to work before.

Gona take a closer look at #1237 now

BenMcH added a commit to BenMcH/web-std-io that referenced this pull request Jul 1, 2022
node-fetch PR that this work is based upon:
node-fetch/node-fetch#1222
jacob-ebey added a commit to remix-run/web-std-io that referenced this pull request Jul 14, 2022
node-fetch PR that this work is based upon: node-fetch/node-fetch#1222

Co-authored-by: Jacob Ebey <jacob.ebey@live.com>
MichaelDeBoey pushed a commit to MichaelDeBoey/web-std-io that referenced this pull request Aug 26, 2023
node-fetch PR that this work is based upon: node-fetch/node-fetch#1222

Co-authored-by: Jacob Ebey <jacob.ebey@live.com>
Gozala pushed a commit to web-std/io that referenced this pull request Aug 28, 2023
* Backport node-fetch redirect bugfix

node-fetch PR that this work is based upon: node-fetch/node-fetch#1222

Co-authored-by: Jacob Ebey <jacob.ebey@live.com>

* chore: fix changeset

---------

Co-authored-by: Ben <benjamin.mchone@gmail.com>
Co-authored-by: Jacob Ebey <jacob.ebey@live.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Getting 403 while trying to fetch html data. 3.0.0 beta.10: TypeError: Cannot read property 'body' of null
4 participants