Prevent listen from reading from nulled out web socket.

This commit is contained in:
Chris Rhodes 2016-01-21 11:11:18 -08:00
parent bf5ca4d690
commit d6d6c749ea

View file

@ -73,7 +73,7 @@ func (s *Session) Open() (err error) {
// Create listening outside of listen, as it needs to happen inside the mutex // Create listening outside of listen, as it needs to happen inside the mutex
// lock. // lock.
s.listening = make(chan interface{}) s.listening = make(chan interface{})
go s.listen(s.listening) go s.listen(s.wsConn, s.listening)
s.Unlock() s.Unlock()
@ -112,9 +112,9 @@ func (s *Session) Close() (err error) {
// listen polls the websocket connection for events, it will stop when // listen polls the websocket connection for events, it will stop when
// the listening channel is closed, or an error occurs. // the listening channel is closed, or an error occurs.
func (s *Session) listen(listening <-chan interface{}) { func (s *Session) listen(wsConn *websocket.Conn, listening <-chan interface{}) {
for { for {
messageType, message, err := s.wsConn.ReadMessage() messageType, message, err := wsConn.ReadMessage()
if err != nil { if err != nil {
// There has been an error reading, Close() the websocket so that // There has been an error reading, Close() the websocket so that
// OnDisconnect is fired. // OnDisconnect is fired.