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

Vite http proxy stuck with unhandled underlying error #4886

Closed
7 tasks done
furkanmustafa opened this issue Sep 9, 2021 · 3 comments
Closed
7 tasks done

Vite http proxy stuck with unhandled underlying error #4886

furkanmustafa opened this issue Sep 9, 2021 · 3 comments

Comments

@furkanmustafa
Copy link

furkanmustafa commented Sep 9, 2021

Describe the bug

The proxy in our setup is failing with Parse Error: Invalid header value char, probably because the server (Azure, not surprisingly) sending garbage in headers. It's okay if the request cannot be proxied in this case, but no response is returned to the client, and any further requests are blocked as well.

Happens on both nodejs v12 and v14, both with option --insecure-http-parser and without.

If --insecure-http-parser is given, the process completely exits on crash.
If --insecure-http-parser is not given, only the proxy gets stuck, dev server continues to work.

Reproduction

Reproduction would need a server that sends garbage in response to be set up as a proxy target. One example was discussed here nodejs/http-parser#520 probably any Imperva WAF endpoint would work, randomly depending on the set-cookie header's value.

// vite.config.js
import vue from '@vitejs/plugin-vue';
import path from 'path';

// https://vitejs.dev/config/
const config = {
	plugins: [ vue() ],
	resolve: {
		alias: {
			'@': path.resolve(__dirname, '/src'),
		},
	},
	server: {
		port: 3001,
		proxy: {
			'/api': {
				target: 'https://an-imperva-azure-awf-hosted-endpoint.com', // cannot provide this myself
				ws: true,
				changeOrigin: true,
			},
		},
	}
};

export default config;

and run;

npx --no-install vite # to start the server

and

curl -v http://localhost:3001/api/something

would cause the error, depending on the headers from upstream server being proxied.

System Info

nodejs v12, v14

Used Package Manager

npm

Logs

normal (without --insecure-http-parser);

npx --no-install vite "--host" "0.0.0.0"


  vite v2.5.1 dev server running at:

  > Local:    http://localhost:3001/
  > Network:  http://10.0.76.118:3001/
  > Network:  http://10.1.45.121:3001/
  > Network:  http://10.0.44.121:3001/
  > Network:  http://172.17.0.1:3001/
  > Network:  http://172.19.0.1:3001/
  > Network:  http://172.28.0.1:3001/

  ready in 658ms.

6:18:56 AM [vite] http proxy error:
Error: Parse Error: Invalid header value char
    at TLSSocket.socketOnData (_http_client.js:509:22)
    at TLSSocket.emit (events.js:315:20)
    at TLSSocket.EventEmitter.emit (domain.js:467:12)
    at addChunk (internal/streams/readable.js:309:12)
    at readableAddChunk (internal/streams/readable.js:284:9)
    at TLSSocket.Readable.push (internal/streams/readable.js:223:10)
    at TLSWrap.onStreamRead (internal/stream_base_commons.js:188:23

with --insecure-http-parser;

  vite:time 450ms /node_modules/.vite/chunk-VYEQUVMN.js?v=9b29af36 +52ms
  vite:load 57ms  [fs] /node_modules/.vite/vue-router.js?v=9b29af36 +43ms
  vite:transform 5ms   /node_modules/.vite/vue-router.js?v=9b29af36 +34ms
  vite:time 74ms  /node_modules/.vite/vue-router.js?v=9b29af36 +23ms
_http_outgoing.js:552
    throw new ERR_INVALID_CHAR('header content', name);
    ^

TypeError [ERR_INVALID_CHAR]: Invalid character in header content ["set-cookie"]
    at ServerResponse.setHeader (_http_outgoing.js:561:3)
    at setHeader (/home/user/dev/app/node_modules/vite/dist/node/chunks/dep-972722fa.js:63565:15)
    at /home/user/dev/app/node_modules/vite/dist/node/chunks/dep-972722fa.js:63591:7
    at Array.forEach (<anonymous>)
    at Array.writeHeaders (/home/user/dev/app/node_modules/vite/dist/node/chunks/dep-972722fa.js:63586:35)
    at ClientRequest.<anonymous> (/home/user/dev/app/node_modules/vite/dist/node/chunks/dep-972722fa.js:65320:22)
    at ClientRequest.emit (events.js:315:20)
    at ClientRequest.EventEmitter.emit (domain.js:467:12)
    at HTTPParser.parserOnIncomingClient [as onIncoming] (_http_client.js:641:27)
    at HTTPParser.parserOnHeadersComplete (_http_common.js:126:17) {
  code: 'ERR_INVALID_CHAR'
}
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! app@0.0.0 dev: `npx --no-install --node-arg --insecure-http-parser vite "--host" "0.0.0.0" "-d"`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the app@0.0.0 dev script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     /home/node/.nodecache/npm/_logs/2021-09-09T05_55_31_698Z-debug.log

Validations

@jet10000
Copy link

[vite] http proxy error:

@dipiash
Copy link

dipiash commented Jun 20, 2022

Hello! What news about this problem?

Might be you could apply this patch http-party/node-http-proxy#1395 from library?

I see that code from node-http-proxy bundled in vite node_modules

@sapphi-red
Copy link
Member

sapphi-red commented Jul 23, 2022

Closing as I confirmed the latest version does not be stucked.
https://github.com/sapphi-red-repros/vite-proxy-invalid-header-repro

related: #7398

@github-actions github-actions bot locked and limited conversation to collaborators Aug 7, 2022
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

4 participants