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

Fix panic #236

Open
wants to merge 24 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
print unwritten msg when ws conn broken
mm2175 committed Jan 7, 2022
commit 3796664c742ea9abd93ef8eb9b2297f2a6f33e47
20 changes: 13 additions & 7 deletions v2/websocket/transport.go
Original file line number Diff line number Diff line change
@@ -144,25 +144,31 @@ func (w *ws) listenWriteChannel() {

select {
case <-w.kill: // ws closed
unWriteNum := len(w.writeChan)
if unWriteNum > 0 {
for i := 0; i < unWriteNum; i++ {
m := <-w.writeChan
w.log.Errorf("%s ws killed with unwritten msg: %v", w.connStr, string(m))
}
}
w.printUnWrittenMsg()
return
case message := <-w.writeChan:
err := w.ws.WriteMessage(websocket.TextMessage, message)
if err != nil {
w.log.Errorf("%s Unable to write to ws: %v", w.connStr, err)
w.stop(err)
w.printUnWrittenMsg()
return
}
}
}
}

func (w *ws) printUnWrittenMsg() {
unWriteNum := len(w.writeChan)
if unWriteNum == 0 {
return
}
for i := 0; i < unWriteNum; i++ {
m := <-w.writeChan
w.log.Errorf("%s ws killed with %d of %d unwritten msg: %v", w.connStr, i, unWriteNum, string(m))
}
}

// listen on ws & fwd to listen()
func (w *ws) listenWs() {
for {