question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

WS proxy websocket connection fails with "Invalid frame header" intermittently

See original GitHub issue

Expected behavior

  • Client should always be able to connect to websocket connection via node.js proxy server.

Actual behavior

Client was able to connect websocket connection via node.js proxy server on deployment but connections started intermittently failing with following errors after few hours:

  • Chrome: “WebSocket connection to ‘ws://<server_dns>/subscriptions’ failed: Invalid frame header”
  • Safari: “WebSocket connection to ‘ws://<server_dns>/subscriptions’ failed: Compressed bit must be 0 if no negotiated deflate-frame extension”

And I see following logs at server side:

13/12/2017 16:01:49[HPM] Client disconnected
13/12/2017 16:02:00[HPM] Upgrading to WebSocket
13/12/2017 16:02:11[HPM] Client disconnected
13/12/2017 16:02:13[HPM] Upgrading to WebSocket
13/12/2017 16:02:13[HPM] Client disconnected
13/12/2017 16:02:15[HPM] Upgrading to WebSocket
13/12/2017 16:02:50[HPM] Client disconnected
13/12/2017 16:03:00[HPM] Upgrading to WebSocket
13/12/2017 16:03:00[HPM] Client disconnected
13/12/2017 16:03:05[HPM] Client disconnected
13/12/2017 16:03:09[HPM] Upgrading to WebSocket
13/12/2017 16:03:10[HPM] Upgrading to WebSocket
13/12/2017 16:03:10[HPM] Client disconnected
13/12/2017 16:03:30[HPM] Upgrading to WebSocket
13/12/2017 16:03:30[HPM] Client disconnected
13/12/2017 16:03:40[HPM] Upgrading to WebSocket
13/12/2017 16:03:40[HPM] Client disconnected
13/12/2017 16:03:59[HPM] Client disconnected
13/12/2017 16:04:00[HPM] Upgrading to WebSocket
13/12/2017 16:04:00[HPM] Client disconnected
13/12/2017 16:04:05[HPM] Upgrading to WebSocket
13/12/2017 16:04:05[HPM] Client disconnected
13/12/2017 16:04:14[HPM] Upgrading to WebSocket
13/12/2017 16:04:20[HPM] Upgrading to WebSocket
13/12/2017 16:05:04[HPM] Client disconnected
13/12/2017 16:05:10[HPM] Client disconnected
13/12/2017 16:05:15[HPM] Upgrading to WebSocket

Setup

Node module versions:

  • http-proxy-middleware: 0.17.4
  • server: express 4.14.0

Server deployment configuration:

  • Node.js server and websocket proxy server, it tries to connect to, are both deployed within docker containers.

proxy middleware configuration


let subscriptionProxyOption = {
    target: <proxy_server_dns>,
    changeOrigin: true,
    ws: true,
    pathRewrite: {
        '/graphql-subscription': ''
    }
}
var subscriptionProxy = proxy('/graphql-subscription', subscriptionProxyOption);

server mounting

var app = express();

app.use(subscriptionProxy);
let server = app.listen(process.env.PORT);
server.on('upgrade', subscriptionProxy.upgrade)

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:10 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
dcworldwidecommented, Aug 12, 2022

Anyone resolve this? It’s a constant issue for us, we can’t connect to our websocket endpoint via http proxy middleware at all since upgrading from 3

1reaction
moeiscoolcommented, Apr 5, 2018

@raeesaa what changes were made?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Invalid frame header - Stack Overflow
I am using NodeJS as a server and Socket.IO, to achieve my real time functionality. The problem is I am getting error as:...
Read more >
Writing WebSocket servers - Web APIs | MDN
The Sec-WebSocket-Accept header is important in that the server must derive it from the Sec-WebSocket-Key that the client sent to it.
Read more >
RFC 6455: The WebSocket Protocol
1. If the connection is happening on an HTTPS (HTTP-over-TLS) port, perform a TLS handshake over the connection. · 2. The server can...
Read more >
Troubleshooting connection issues | Socket.IO
You are trying to reach a plain WebSocket server; The server is not reachable; The client is not compatible with the version of...
Read more >
WebSocket - The Modern JavaScript Tutorial
That's because ws:// data is not encrypted, visible for any intermediary. Old proxy servers do not know about WebSocket, they may see “strange” ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found