Websocket closes connection after few ping messages
Opened this issue · 5 comments
-
Time: 2023-07-12T09:16:59.236Z
-
Which endpoints are you having problems with
https://finnhub.io/docs/api/websocket-press-releases -
How to reproduce the error and what is the expected result?
Take an example from respective part of documentation and run the code. I assume connection should live as expected
After successful open
event server sends me ping
messages. After very random number such messages connection closes despite i emit pong
in response
Code example
const WebSocket = require("ws");
const socket = new WebSocket(
"wss://ws.finnhub.io?token=<my-api-token>"
);
// Connection opened -> Subscribe
socket.addEventListener("open", function (event) {
console.log("WebSocket is opened");
socket.send(JSON.stringify({ type: "subscribe-pr", symbol: "AAPL" }));
socket.send(JSON.stringify({ type: "subscribe-pr", symbol: "MSFT" }));
socket.send(JSON.stringify({ type: "subscribe-pr", symbol: "AMZN" }));
});
// Listen for messages
socket.addEventListener("message", function (event) {
console.log("Message from server ", event.data, new Date().toISOString());
if (event.data.type === 'ping') {
socket.send(JSON.stringify({ type: 'pong' }))
}
});
socket.addEventListener("close", () => {
console.log("Connection closed");
});
// Unsubscribe
var unsubscribe = function (symbol) {
socket.send(JSON.stringify({ type: "unsubscribe-pr", symbol: symbol }));
};
Raising the topic! I have exactly the same problem!
Will anyone help?
Same issue although I'm using Java not python. Closes with code 1006 randomly. I've gotten around it by reconnecting when it closes unexpectedly, but not a great solution.
bumping up , having the same problem in java implementation
+1 golang
+1 golang. connection just goes silent. gorilla client returns 1006