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

Parse Error: Expected HTTP #9172

Closed
7 tasks done
stuta opened this issue Jul 17, 2022 · 2 comments · Fixed by #9175 or #9193
Closed
7 tasks done

Parse Error: Expected HTTP #9172

stuta opened this issue Jul 17, 2022 · 2 comments · Fixed by #9175 or #9193
Labels
p3-minor-bug An edge case that only affects very specific usage (priority)

Comments

@stuta
Copy link

stuta commented Jul 17, 2022

Describe the bug

Vite 3 crashes when getting a big proxy answer.

[vite] http proxy error:
Error: Parse Error: Expected HTTP/
    at Socket.socketOnData (node:_http_client:521:22)
    at Socket.emit (node:events:513:28)
    at addChunk (node:internal/streams/readable:324:12)
    at readableAddChunk (node:internal/streams/readable:297:9)
    at Readable.push (node:internal/streams/readable:234:10)
    at TCP.onStreamRead (node:internal/stream_base_commons:190:23)
node:_http_outgoing:603
    throw new ERR_HTTP_HEADERS_SENT('set');
    ^

Error [ERR_HTTP_HEADERS_SENT]: Cannot set headers after they are sent to the client
    at new NodeError (node:internal/errors:387:5)
    at ServerResponse.setHeader (node:_http_outgoing:603:11)
    at ServerResponse.writeHead (node:_http_server:330:21)
    at ProxyServer.<anonymous> (file:///Users/pasi/nc/nc-designer/node_modules/.pnpm/vite@3.0.0_sass@1.53.0/node_modules/vite/dist/node/chunks/dep-561c5231.js:56942:18)
    at ProxyServer.emit (file:///Users/pasi/nc/nc-designer/node_modules/.pnpm/vite@3.0.0_sass@1.53.0/node_modules/vite/dist/node/chunks/dep-561c5231.js:55119:28)
    at ClientRequest.proxyError (file:///Users/pasi/nc/nc-designer/node_modules/.pnpm/vite@3.0.0_sass@1.53.0/node_modules/vite/dist/node/chunks/dep-561c5231.js:56461:18)
    at ClientRequest.emit (node:events:513:28)
    at Socket.socketOnData (node:_http_client:530:9)
    at Socket.emit (node:events:513:28)
    at addChunk (node:internal/streams/readable:324:12) {
  code: 'ERR_HTTP_HEADERS_SENT'
}

Node.js v18.6.0
 ELIFECYCLE  Command failed with exit code 1.

Trouble is a long answer, Content-Length: 426151, Content-Encoding: gzip. Uncompressed json length is 7024908.
This is my Vite proxy config:

proxy: {
    '/rest': {
        target: 'http://127.0.0.1:5959',
        proxyTimeout: 6000 * 60 * 1000,
        onProxyReq: (proxyReq, req) => req.setTimeout(6000 * 60 * 1000),
        keepalive: true
    }
}

Wireshark follow-http:

Screenshot 2022-07-14 at 3 28 31

I found this: https://stackoverflow.com/questions/67462137/why-does-this-http-response-stream-yield-a-parsing-error
I guess Vite should handle this situation?

Vite 2 gives proxy error too, but it works and does not crash.

Reproduction

System Info

System:
    OS: macOS 13.0
    CPU: (8) arm64 Apple M1 Pro
    Memory: 436.45 MB / 16.00 GB
    Shell: 5.8.1 - /bin/zsh
  Binaries:
    Node: 18.6.0 - ~/.nvm/versions/node/v18.6.0/bin/node
    npm: 8.13.2 - ~/.nvm/versions/node/v18.6.0/bin/npm
  Browsers:
    Chrome: 103.0.5060.114
    Firefox: 102.0.1
    Safari: 16.0
  npmPackages:
    @vitejs/plugin-legacy: ^2.0.0 => 2.0.0
    @vitejs/plugin-vue: ^3.0.0 => 3.0.0
    vite: ^3.0.0 => 3.0.0

Used Package Manager

pnpm

Logs

No response

Validations

@stuta
Copy link
Author

stuta commented Jul 18, 2022

Version 3.0.1 did not fix the crash.

[vite] http proxy error:
Error: Parse Error: Expected HTTP/
    at Socket.socketOnData (node:_http_client:521:22)
    at Socket.emit (node:events:513:28)
    at addChunk (node:internal/streams/readable:324:12)
    at readableAddChunk (node:internal/streams/readable:297:9)
    at Readable.push (node:internal/streams/readable:234:10)
    at TCP.onStreamRead (node:internal/stream_base_commons:190:23)
node:_http_outgoing:603
    throw new ERR_HTTP_HEADERS_SENT('set');
    ^

Error [ERR_HTTP_HEADERS_SENT]: Cannot set headers after they are sent to the client
    at new NodeError (node:internal/errors:387:5)
    at ServerResponse.setHeader (node:_http_outgoing:603:11)
    at ServerResponse.writeHead (node:_http_server:330:21)
    at ProxyServer.<anonymous> (file:///Users/pasi/nc/nc-designer/node_modules/.pnpm/vite@3.0.1_sass@1.53.0/node_modules/vite/dist/node/chunks/dep-10d8d214.js:56975:26)
    at ProxyServer.emit (file:///Users/pasi/nc/nc-designer/node_modules/.pnpm/vite@3.0.1_sass@1.53.0/node_modules/vite/dist/node/chunks/dep-10d8d214.js:55148:28)
    at ClientRequest.proxyError (file:///Users/pasi/nc/nc-designer/node_modules/.pnpm/vite@3.0.1_sass@1.53.0/node_modules/vite/dist/node/chunks/dep-10d8d214.js:56490:18)
    at ClientRequest.emit (node:events:513:28)
    at Socket.socketOnData (node:_http_client:530:9)
    at Socket.emit (node:events:513:28)
    at addChunk (node:internal/streams/readable:324:12) {
  code: 'ERR_HTTP_HEADERS_SENT'
}

@stuta
Copy link
Author

stuta commented Jul 18, 2022

Vite 3.0.2 does not crash and it works, still the same error as in Vite 2.

[vite] http proxy error:
Error: Parse Error: Expected HTTP/
    at Socket.socketOnData (node:_http_client:521:22)
    at Socket.emit (node:events:513:28)
    at addChunk (node:internal/streams/readable:324:12)
    at readableAddChunk (node:internal/streams/readable:297:9)
    at Readable.push (node:internal/streams/readable:234:10)
    at TCP.onStreamRead (node:internal/stream_base_commons:190:23)

@github-actions github-actions bot locked and limited conversation to collaborators Aug 2, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
p3-minor-bug An edge case that only affects very specific usage (priority)
Projects
None yet
3 participants