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 connections getting closed #2

Open
adrpino opened this issue May 17, 2018 · 10 comments
Open

Websocket connections getting closed #2

adrpino opened this issue May 17, 2018 · 10 comments

Comments

@adrpino
Copy link

adrpino commented May 17, 2018

I am attempting to run the example and when reading data from the websocket I get the following error:

level=error time=2018-05-17T21:12:47.556428787Z caller=service_websocket.go:35 wsRead="websocket: close 1008 (policy violation): {\"code\":-1,\"msg\":\"Illegal format ws or stream\"}"

Has the API changed in some way and some adaptations are required? I remember using this package months ago and worked like a bliss.

If you need help with it I'm willing to give a hand

@rootpd
Copy link
Owner

rootpd commented May 18, 2018

Hi, to be honest I have no idea. It's a bit more alive at official fork here https://github.com/binance-exchange/go-binance/ - at least PR-wise.

I haven't seen or used the APIs for a while now but looking at the error it looks that something with Websocket APIs really changed. I'll keep this open just in case I got back to this some day.

@theMattCode
Copy link

Got that error, too.
Issues are not activated in the fork project.

@sinyakinilya
Copy link

This error/issue happens when goroutine exitHandler sends message 1 second.

		case t := <-ticker.C:
			err := c.WriteMessage(websocket.TextMessage, []byte(t.String()))
			if err != nil {
				level.Error(as.Logger).Log("wsWrite", err)
				return
			}

It works fine without "send" message

@Jolly23
Copy link

Jolly23 commented Jun 29, 2018

@sinyakinilya How to fix?

@Jolly23
Copy link

Jolly23 commented Jun 29, 2018

@rootpd @adrpino @sinyakinilya @betazoid
If I delete service_websocket.go line 414~419, it works fine.
But I do not know what error will occur since I deleted that part of codes.

@crlrfzj
Copy link

crlrfzj commented Jul 26, 2018

I use conn.NextWriter instead of conn.WriteMessage to write msg and it works well.

w, err := conn.NextWriter(websocket.TextMessage)
if err != nil {
	logger.Error(err.Error())
	return
}
w.Write([]byte(msg))

@kiennt23
Copy link

I use conn.NextWriter instead of conn.WriteMessage to write msg and it works well.

w, err := conn.NextWriter(websocket.TextMessage)
if err != nil {
	logger.Error(err.Error())
	return
}
w.Write([]byte(msg))

Has anyone fixed this issue? I tried using the fix from @crlrfzj but it doesn't work.

@jloup
Copy link

jloup commented Feb 25, 2019

exitHandler in service_websocket.go is sending unsollicited text message to server every second.

I do not see the need for sending this message every second.

Binance api docs says :

The websocket server will send a ping frame every 3 minutes. If the websocket server does not receive a pong frame back from the connection within a 10 minute period, the connection will be disconnected. Unsolicited pong frames are allowed

But gorilla websocket handle PING/PONG frames on its own.

Two solutions that worked for me :

  • Remove in ticker :
    err := c.WriteMessage(websocket.TextMessage, []byte("--heartbeat--"))
    if err != nil {
    level.Error(as.Logger).Log("wsWrite", err)
    return
    }
  • OR replace websocket.TextMessage by websocket.PongMessage as unsolicited pong frames are allowed

@kiennt23
Copy link

Remove ticker is a better solution IMO. I created a PR for the fix

@filinvadim
Copy link

filinvadim commented Jul 13, 2020

Removed it.
I support this repo here: https://github.com/filinvadim/go-binance

Update: i have special wss client for echange wss endpoints - https://github.com/filinvadim/stubborn. Welcome!

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

9 participants