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

http proxy error ECONNRESET at TLSWrap.onStreamRead #4794

Closed
7 tasks done
steveoh opened this issue Aug 30, 2021 · 7 comments
Closed
7 tasks done

http proxy error ECONNRESET at TLSWrap.onStreamRead #4794

steveoh opened this issue Aug 30, 2021 · 7 comments

Comments

@steveoh
Copy link

steveoh commented Aug 30, 2021

Describe the bug

When using the vite proxy every request that goes through it throws

10:46:37 AM [vite] http proxy error:
Error: read ECONNRESET
    at TLSWrap.onStreamRead (node:internal/stream_base_commons:220:20) (x8)

The request succeeds but the console is cluttered by these logs.

In my research, I've seen that this can be an issue with many parts of the equation (nodejs, the api, etc) and I did try to chat in discord but it seems a bit too specific to get any interest. If this isn't a bug in vite, I would appreciate some tips with my configuration or items to check for with the api or nodejs versions. This would be useful information for the docs once solved.

Reproduction

I a using a dotnet core 5 api with the vite configuration of

dotnet new webapi

proxy: {
      '/api': {
        target: 'https://localhost:5001/',
        changeOrigin: true,
        secure: false,
        protocolRewrite: 'https',
        cookieDomainRewrite: 'localhost:3000',
      },
    },

System Info

System:
    OS: macOS 11.5.2
    CPU: (16) x64 Intel(R) Core(TM) i9-9880H CPU @ 2.30GHz
    Memory: 853.84 MB / 32.00 GB
    Shell: 5.8 - /bin/zsh
  Binaries:
    Node: 16.8.0 - /usr/local/bin/node
    npm: 7.21.0 - /usr/local/bin/npm
  Browsers:
    Chrome: 92.0.4515.159
    Firefox: 90.0.2
    Safari: 14.1.2
  npmPackages:
    vite: ^2.5.1 => 2.5.1

Used Package Manager

npm

Logs

No response

Validations

@JohnCampionJr
Copy link

I have this issue too; but only on one Mac (M1) and not another (Intel). Will try to figure out what the difference is ASAP.

@JohnCampionJr
Copy link

JohnCampionJr commented Oct 31, 2021

OK, So a little more work and I have some findings that may or may not help find this.

On my old Mac (Intel 6 core), with Node 14, I can only get this to happen if I just hit refresh on the proxy'd URL from Chrome several times in a row. With Node 16, it happens every time I load the proxy'd URL.

On my new Mac (M1 Pro), I only have Node 16 installed, so I see it every load too.

On a Windows computer, I don't have this issue at all.

Other than this error, it actually works fine in all cases. Maybe just need some way to suppress the error?

@JohnCampionJr
Copy link

JohnCampionJr commented Nov 2, 2021

I found a workaround. It seems to be a bug in http-proxy related to this issue:

http-party/node-http-proxy#1496

This patch from 7 years ago does not seem to be needed any longer but http-proxy hasn't been updated in 3 years.

The solution is to set an Agent in the proxy which will avoid the close code being run.

In my proxy.conf.ts:

import https from 'https'

const proxy = {
  target,
  secure: false,
  agent: new https.Agent()
}

With that code in place, I no longer get the errors.

If you're not using https, use http for the import.

@steveoh
Copy link
Author

steveoh commented Nov 19, 2021

What is target in this snippet?

proxy.conf.ts:

import https from 'https'

const proxy = {
  target,
  secure: false,
  agent: new https.Agent()
}

@maxicarlos08
Copy link

This might be unrelated, but im having similar problems on a Vue project (without vite?) and Node v17, here my system info if it helps you:

  System:
    OS: Linux 5.15 Arch Linux
    CPU: (12) x64 AMD Ryzen 5 5500U with Radeon Graphics
    Memory: 5.37 GB / 13.58 GB
    Container: Yes
    Shell: 5.8 - /usr/bin/zsh
  Binaries:
    Node: 17.1.0 - /usr/bin/node
    npm: 8.1.3 - /usr/bin/npm
  Browsers:
    Firefox: 94.0.2

@sapphi-red
Copy link
Member

I use server.proxy with Node.js 18 but I never faced this issue.
Would anyone provide a reproduction? Ideally with Node.js or with Docker (as it's easy for me).
Without a repro, it's difficult to find what is not working here.

@github-actions
Copy link

Hello @steveoh. Please provide a minimal reproduction using a GitHub repository or StackBlitz. Issues marked with need reproduction will be closed if they have no activity within 3 days.

@github-actions github-actions bot closed this as not planned Won't fix, can't repro, duplicate, stale Apr 23, 2023
@github-actions github-actions bot locked and limited conversation to collaborators May 7, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

5 participants