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

panic: repeated read on failed websocket connection #476

Closed
sdjyliqi opened this issue Jan 31, 2019 · 4 comments
Closed

panic: repeated read on failed websocket connection #476

sdjyliqi opened this issue Jan 31, 2019 · 4 comments

Comments

@sdjyliqi
Copy link

type WsConn struct {
*websocket.Conn
proxy string
host string
path string
closed bool
....................
}

func (ws *WsConn) StartToReceiveMessage() {
go func() {
for {
t, msg, err := ws.ReadMessage() // this line caused the panic
if ws.closed {
glog.V(7).Infof("websocket closed.....")
return
}
ws.fireMessage(err, t, msg)
}
}()
}

I create the connection to the server and subsribe some api.
run after few seconds.....

panic: repeated read on failed websocket connection

goroutine 69 [running]:
github.com/gorilla/websocket.(*Conn).NextReader(0xc00017a160, 0xc000092008, 0xc0003f1fa8, 0x2, 0x2, 0xb)
D:/GoWork/src/github.com/gorilla/websocket/conn.go:968 +0x35d
github.com/gorilla/websocket.(*Conn).ReadMessage(0xc00017a160, 0x2, 0x2, 0xb, 0x0, 0x0, 0xc0002402c0)
D:/GoWork/src/github.com/gorilla/websocket/conn.go:1029 +0x36

Process finished with exit code 2

@elithrar
Copy link
Contributor

elithrar commented Jan 31, 2019 via email

@garyburd
Copy link
Contributor

garyburd commented Feb 1, 2019

Break out of the loop on error.

@TangMonk
Copy link

I still encounter this problem, Is the bug fixed?

@elithrar
Copy link
Contributor

t, msg, err := ws.ReadMessage() // this line caused the panic

You need to handle the error and break out of the loop.

@TangMonk - without your code it's not clear if you have the same problem, but this is likely a bug in your application code, not in websocket.

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

Successfully merging a pull request may close this issue.

4 participants