You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Proxy error on second and further connections (express, http-proxy-middleware) #3062
The first websocket connection after starting the server is fine.
The second and any later connection fails.
Error on server:
[HPM] Upgrading to WebSocket
[HPM] Error occurred while trying to proxy request /socket.io/?EIO=3&transport=websocket&sid=c6vi4Jz2M_NwmzSSAAAD from localhost:3000 to http://localhost:8885 (ECONNRESET) (https://nodejs.org/api/errors.html#errors_common_system_errors)
Error in Chrome:
websocket.js:112 WebSocket connection to 'ws://localhost:3000/socket.io/?EIO=3&transport=websocket&sid=c6vi4Jz2M_NwmzSSAAAD' failed: One or more reserved bits are on: reserved1 = 1, reserved2 = 0, reserved3 = 0
Error in Firefox:
The connection to http://localhost:3000/__webpack_hmr was interrupted while the page was loading.
Steps to reproduce (if the current behaviour is a bug)
Define a websocket proxy with http-proxy-middleware: app.use('/__webpack_hmr', proxy({ws: true}));
Integrate socket.io with express: require('socket.io')(server);
Start two client sessions, one after the other
Observe logs:
a. The server handles the first websocket connection correctly.
b. The second websocket connection seems to be delegated to the wildcard proxy.
Expected behaviour
Both client sessions manage to connect.
Setup
OS: arch linux
browser: Chrome, Firefox
socket.io version: 2.0.3
Other information (e.g. stacktraces, related issues, suggestions how to fix)
Fix: Pass the path to the proxy() call instead of app.use(). (see comment below)
changed the title [-][Express] Proxy error on second and later connection[/-][+][Express] Proxy error on second and further connections[/+]on Sep 26, 2017
changed the title [-][Express] Proxy error on second and further connections[/-][+][Express] Proxy error on second and further connections when using `.get('/*'`[/+]on Sep 26, 2017
changed the title [-][Express] Proxy error on second and further connections when using `.get('/*'`[/-][+][Express] Proxy error on second and further connections when using .get('/*'[/+]on Sep 26, 2017
changed the title [-][Express] Proxy error on second and further connections when using .get('/*'[/-][+]Proxy error on second and further connections (express, http-proxy-middleware)[/+]on Sep 27, 2017
Activity
[-][Express] Proxy error on second and later connection[/-][+][Express] Proxy error on second and further connections[/+][-][Express] Proxy error on second and further connections[/-][+][Express] Proxy error on second and further connections when using `.get('/*'`[/+][-][Express] Proxy error on second and further connections when using `.get('/*'`[/-][+][Express] Proxy error on second and further connections when using .get('/*'[/+]ftes commentedon Sep 27, 2017
Update: It seems this is rather an express issue.
The problem was with a
/__webpack_hmrproxy that also used a websocket.The following code "hijacked" the socket.io websocket and proxied it:
The trick is to not rely on express to perform the path matching, and move the
/__webpack_hmrcontext to the proxy call:[-][Express] Proxy error on second and further connections when using .get('/*'[/-][+]Proxy error on second and further connections (express, http-proxy-middleware)[/+]