Ver código fonte

Do not call session onEvent as goroutine

This is a stability improvement but may have a slight performance
impact. This change will be reviewed again later.  Doing this solves a
data race issue with the Sequence number that must be tracked for
gateway resume and heartbeats.  Event specific handlers are now called
as a goroutine though.
Bruce Marriner 8 anos atrás
pai
commit
face6df4b6
1 arquivos alterados com 3 adições e 3 exclusões
  1. 3 3
      wsapi.go

+ 3 - 3
wsapi.go

@@ -161,7 +161,7 @@ func (s *Session) listen(wsConn *websocket.Conn, listening <-chan interface{}) {
 			return
 
 		default:
-			go s.onEvent(messageType, message)
+			s.onEvent(messageType, message)
 
 		}
 	}
@@ -377,7 +377,7 @@ func (s *Session) onEvent(messageType int, message []byte) {
 		// it's better to pass along what we received than nothing at all.
 		// TODO: Think about that decision :)
 		// Either way, READY events must fire, even with errors.
-		s.handle(i)
+		go s.handle(i)
 
 	} else {
 		s.log(LogWarning, "unknown event: Op: %d, Seq: %d, Type: %s, Data: %s", e.Operation, e.Sequence, e.Type, string(e.RawData))
@@ -385,7 +385,7 @@ func (s *Session) onEvent(messageType int, message []byte) {
 
 	// Emit event to the OnEvent handler
 	e.Struct = i
-	s.handle(e)
+	go s.handle(e)
 }
 
 // ------------------------------------------------------------------------------------------------