olahol / melody

:notes: Minimalist websocket framework for Go
BSD 2-Clause "Simplified" License
3.75k stars 366 forks source link

writeMessage could panic. #8

Closed kgdev closed 9 years ago

kgdev commented 9 years ago

func (s Session) writeMessage(message envelope) { select { case s.output <- message: default: s.melody.errorHandler(s, errors.New("Message buffer full")) } }

Here s.output <- message could panic if s.output is already closed, which causes the whole application to exit.

It looks like the problem is:

panic: [stderr] send on closed channel [stderr] goroutine 72 [running]: [stderr] ....melody.(_Session).writeMessage(0xc8203c6f60, 0xc820342000) .... melody.(_Session).ping

func (s *Session) ping() { s.writeMessage(&envelope{t: websocket.PingMessage, msg: []byte{}}) }

We should use s.writeRaw instead of s.writeMessage in ping().

olahol commented 9 years ago

Nice catch, thank you :+1: