Giter Site home page Giter Site logo

Websocket timeout about go-binance HOT 14 CLOSED

adshao avatar adshao commented on June 14, 2024
Websocket timeout

from go-binance.

Comments (14)

snawaz avatar snawaz commented on June 14, 2024 2

@adshao your project has been a tremendous help. Much appreciated. I recently started seeing many "websocket: close 1008 (policy violation): Pong timeout" messages. I see that this case is closed, but I wonder if this is something you or anyone else is seeing. My code simply restart the a Websocket, but I wonder if I should be doing something diferent.

this is because #50 does not fix the problem, as it sends ping message whereas the client needs to send pong message. As the per the binance docs, it's the server which sends ping to the client and then if the client does not respond with a pong message within 10 mins, then the server will disconnect the connection.

from go-binance.

goriunov avatar goriunov commented on June 14, 2024 1

For future readers, as per @snawaz looks like if you set custom ping handler it will not automatically send pong based on the Gorilla websocket implementation. You will need to send pong back by yourself from within your custom ping handler.

image

This primarily required for the implementation on the gorilla websocket with custom handler. Note that if no handler is passed or no SetPingHandler called, it will default to the default ping handler

from go-binance.

adshao avatar adshao commented on June 14, 2024

hi @davidklodner , thanks for the issue.
for connection timeout, do you mean readdealine as in https://godoc.org/github.com/gorilla/websocket#Conn.SetReadDeadline , I think we can add it as a websocket config; while for ping/pong handler, I cannot find any info about it from binance api doc, and I tested it with https://godoc.org/github.com/gorilla/websocket#Conn.SetPingHandler and https://godoc.org/github.com/gorilla/websocket#Conn.SetPongHandler, there is nothing sent from binance server, I think it's fine to ignore them.
Do you have any better suggestion?

from go-binance.

 avatar commented on June 14, 2024

@adshao Try setting a pong handler and sending the server a ping. If the server correctly implements the websocket protocol, then the application should receive a pong. This may not be documented because it's at the Websocket protocol level, not part of the application.

from go-binance.

adshao avatar adshao commented on June 14, 2024

@claudia-jones thanks for the update, you are right, we can periodically send ping message to server, and check pong message for connection stability.

from go-binance.

kustov-an avatar kustov-an commented on June 14, 2024

Hi! Any updates on this?

from go-binance.

adshao avatar adshao commented on June 14, 2024

hi @kustov-an , will implement it soon.

from go-binance.

adshao avatar adshao commented on June 14, 2024

I don't think we need ping/pong handler here, instead, HandshakeTimeout https://godoc.org/github.com/gorilla/websocket#Dialer and CloseHandler https://godoc.org/github.com/gorilla/websocket#Conn.SetCloseHandler are enough to check connection stability.
Since these changes will break the compatibility, we need to refactor the web socket interfaces.

from go-binance.

kustov-an avatar kustov-an commented on June 14, 2024

Correct me if I wrong, but as I understand

  1. HandshakeTimeout is only used when establishing a new connection
  2. CloseHandler is executed when the connection is closed by the peer
    So those changes are not going to help when the connection is lost due to network problems?

from go-binance.

adshao avatar adshao commented on June 14, 2024

hi @kustov-an , if the connection is lost, ReadMessage will return error: https://github.com/adshao/go-binance/blob/master/websocket.go#L45, so we can use errHandler here.

from go-binance.

kustov-an avatar kustov-an commented on June 14, 2024

Hi @adshao, please take a look at my pull request #50 addressing this issue

from go-binance.

adshao avatar adshao commented on June 14, 2024

close as solved

from go-binance.

aleibovici avatar aleibovici commented on June 14, 2024

@adshao your project has been a tremendous help. Much appreciated. I recently started seeing many "websocket: close 1008 (policy violation): Pong timeout" messages. I see that this case is closed, but I wonder if this is something you or anyone else is seeing. My code simply restart the a Websocket, but I wonder if I should be doing something diferent.

from go-binance.

snawaz avatar snawaz commented on June 14, 2024

For future readers, as per @snawaz looks like if you set custom ping handler it will not automatically send pong based on the Gorilla websocket implementation. You will need to send pong back by yourself from within your custom ping handler.

That's correct. I have a custom ping handler which sends websocket.PongMessage, as soon as it receives the PingMessage.

image

from go-binance.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.