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

Bug reproduction: web fetch fails on https://gmail.com and crashes entire server #3404

Closed
wants to merge 1 commit into from

Conversation

vedantroy
Copy link

When we run await fetch("https://gmail.com"), in a loader, we get this error:

    Error: Premature close

        at TLSSocket.<anonymous> (/tmp/remix/node_modules/@remix-run/web-fetch/src/fetch.js:343:32)
        at TLSSocket.emit (node:events:532:35)
        at node:net:687:12
        at TCP.done (node:_tls_wrap:580:7)

On its own, this is no massive issue. The problem is that the server crashes after this, rendering it incapable of handling new requests.

@remix-cla-bot
Copy link
Contributor

remix-cla-bot bot commented Jun 6, 2022

Hi @vedantroy,

Welcome, and thank you for contributing to Remix!

Before we consider your pull request, we ask that you sign our Contributor License Agreement (CLA). We require this only once.

You may review the CLA and sign it by adding your name to contributors.yml.

Once the CLA is signed, the CLA Signed label will be added to the pull request.

If you have already signed the CLA and received this response in error, or if you have any questions, please contact us at hello@remix.run.

Thanks!

- The Remix team

@machour machour added the bug Something isn't working label Jun 7, 2022
@BenMcH
Copy link
Contributor

BenMcH commented Jun 21, 2022

I'm seeing this error occasionally when I am trying to use fetch and get 301 responses. My fetch is already wrapped in a try/catch so I'm not sure how to properly catch this error.

/home/mchone/Documents/projects/remix-rss/node_modules/@remix-run/web-fetch/src/fetch.js:343
                                        const err = Object.assign(new Error('Premature close'), {
                               ^
Error: Premature close
    at TLSSocket.<anonymous> (/home/mchone/Documents/projects/remix-rss/node_modules/@remix-run/web-fetch/src/fetch.js:343:32)
    at TLSSocket.emit (node:events:539:35)
    at node:net:740:14
    at TCP.done (node:_tls_wrap:581:7)

@BenMcH
Copy link
Contributor

BenMcH commented Jun 21, 2022

Downgrading to ~1.4.0 fixes the immediate issue, but a longer term fix is necessary.

@machour
Copy link
Collaborator

machour commented Jun 21, 2022

Probably happened when we moved from node-fetch to @remix-run/web-fetch in #2736

@jacob-ebey 👀

@BenMcH
Copy link
Contributor

BenMcH commented Jun 28, 2022

This has bugs but is allowing me to work around the issue in my specific case.

const fetchWithManualRedirect = (url, opts) => fetch(url, opts = {}).then(res => {
  return [301, 302].includes(res.status) ?
    fetchWithManualRedirect(res.headers.get('location'), {...opts, redirect: 'manual'})
    : res
})

The bug appears to be within the fetch package, specifically around how the redirect options function.

@machour machour added the feat:fetch Issues related to @remix-run/web-fetch label Jun 28, 2022
@jenseng
Copy link
Contributor

jenseng commented Jun 28, 2022

Ran into the same issue a couple months back and the same workaround worked for me (i.e. don't automatically follow redirects).

In my case, the server in question was sending a redirect response w/ chunked transfer encoding. I think this might be the commit that needs to be backported (but it might not be trivial since afaik @remix-run/web-fetch is based on 2.x): node-fetch/node-fetch#1222

@rolfkip
Copy link

rolfkip commented Jun 28, 2022

I am also running into this same error now when requesting a pdf resource with fetch. Using redirect: 'manual' like previous suggestions causes CORS issues, so I haven't been able to identify a workaround yet outside of downgrading.

@BenMcH
Copy link
Contributor

BenMcH commented Jul 14, 2022

Oh, @jacob-ebey, I didn't mean for this issue to actually be closed 🤦‍♂️. The integration of the updated fetch package with remix will fix this one.

Sorry, I thought my phrasing in my PR wouldn't have triggered github's auto-close feature.

@raymclee
Copy link

still having the error after upgrading the version to 1.6.5

@machour
Copy link
Collaborator

machour commented Jul 15, 2022

@raymclee 1.6.5 was released before this got merged. It will be shipped in the next release.
@BenMcH we are used to close issues/PRs as soon as they are fixed in git, without waiting for a release, so nothing to worry about here :)

/cc @jacob-ebey for confirmation of both my claims

@raymclee
Copy link

@raymclee 1.6.5 was released before this got merged. It will be shipped in the next release. @BenMcH we are used to close issues/PRs as soon as they are fixed in git, without waiting for a release, so nothing to worry about here :)

/cc @jacob-ebey for confirmation of both my claims

got it! thanks

@BenMcH
Copy link
Contributor

BenMcH commented Jul 15, 2022

@raymclee 1.6.5 was released before this got merged. It will be shipped in the next release.
@BenMcH we are used to close issues/PRs as soon as they are fixed in git, without waiting for a release, so nothing to worry about here :)

/cc @jacob-ebey for confirmation of both my claims

My concern is that the web-fetch package failed to release and wasn't brought into remix. A release today would not fix the issue.

@machour
Copy link
Collaborator

machour commented Jul 15, 2022

Re-opening for visibility

@machour machour reopened this Jul 15, 2022
@BenMcH
Copy link
Contributor

BenMcH commented Jul 20, 2022

@mcansh just got the web-fetch release cut, so if you delete package-lock.json and your node modules folder, you'll pull in @remix-run/web-fetch v4.2.0 which has the fix for this thread!

@mcansh mcansh closed this Jul 20, 2022
@kiliman
Copy link
Collaborator

kiliman commented Jul 20, 2022

This also appears to work:

npm up @remix-run/web-fetch@latest --no-package-lock

@asinan007
Copy link

Hi @BenMcH i know this seems to be fixed in @remix-run/web-fetch v4.2.0
currently i am using v4.3.2 and for some unknown reason i've started getting this error couple of days ago,
Is there anyway i can go about this;

Screenshot 2022-12-24 at 01 41 43

below are some dependencies;

    "@remix-run/node": "^1.8.0",
    "@remix-run/react": "^1.8.0",
    "@remix-run/serve": "^1.7.2",
    "@remix-run/server-runtime": "1.7.5",
    "react": "^18.2.0",
    "react-dom": "^18.2.0",
    "react-html-parser": "2.0.2",
    "react-i18next": "12.0.0",
    "remix": "1.8.0",
    "remix-i18next": "4.1.1",
    "remix-utils": "4.3.0",

@armando-herastang
Copy link

Hi @BenMcH i know this seems to be fixed in @remix-run/web-fetch v4.2.0 currently i am using v4.3.2 and for some unknown reason i've started getting this error couple of days ago, Is there anyway i can go about this;

Screenshot 2022-12-24 at 01 41 43

below are some dependencies;

    "@remix-run/node": "^1.8.0",
    "@remix-run/react": "^1.8.0",
    "@remix-run/serve": "^1.7.2",
    "@remix-run/server-runtime": "1.7.5",
    "react": "^18.2.0",
    "react-dom": "^18.2.0",
    "react-html-parser": "2.0.2",
    "react-i18next": "12.0.0",
    "remix": "1.8.0",
    "remix-i18next": "4.1.1",
    "remix-utils": "4.3.0",

Having the same issue with @remix-run/node 1.9.0 and @remix-run/web-fetch v4.3.2. Failing on 301 responses
Hoping this get resolved soon!

@gdak
Copy link

gdak commented Jan 17, 2023

Hi @mcansh @BenMcH I'm having the same issue here, for some reason 4.3.2 started to fail/crash with 301 responses.

@danielemery
Copy link

+1 also having this issue

On the first route of the first project I'm trying with remix so not a really good look 😓

The PR looks good to me, would be great to get an approval!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working feat:fetch Issues related to @remix-run/web-fetch
Projects
None yet
Development

Successfully merging this pull request may close these issues.