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

Websocket closes connection after few ping messages #520

Open
Becherman opened this issue Jul 12, 2023 · 5 comments
Open

Websocket closes connection after few ping messages #520

Becherman opened this issue Jul 12, 2023 · 5 comments

Comments

@Becherman
Copy link

  • 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 }));
};
@mcigorli
Copy link

mcigorli commented Oct 9, 2023

Raising the topic! I have exactly the same problem!
Will anyone help?

@Zedron
Copy link

Zedron commented Dec 20, 2023

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.

@bacarin
Copy link

bacarin commented Sep 18, 2024

bumping up , having the same problem in java implementation

@jjjachyty
Copy link

+1 golang

@skyheights
Copy link

+1 golang. connection just goes silent. gorilla client returns 1006

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants