diff --git a/common/connection.go b/common/connection.go index b0bc951f6..ecf368113 100644 --- a/common/connection.go +++ b/common/connection.go @@ -368,6 +368,28 @@ func (c *Connection) recvLoop() { return } + // In some cases the error response will only have the id and error, + // but no sessionId. In these cases we can't guarantee the origin of + // the request and so where the msg should be redirected to. To ensure + // the msg gets to the correct handler (which is potentially blocking + // a test iteration) we need to send it to all sessions and the + // connection's event loop. + case msg.ID != 0 && msg.Error != nil && msg.SessionID == "": + c.sessionsMu.RLock() + for _, s := range c.sessions { + select { + case s.readCh <- &msg: + case code := <-c.closeCh: + c.logger.Debugf("Connection:recvLoop:msg.ID:msg.Error:<-c.closeCh", "sid:%v tid:%v wsURL:%v crashed:%t", s.id, s.targetID, c.wsURL, s.crashed) + _ = c.close(code) + case <-c.done: + c.logger.Debugf("Connection:recvLoop:msg.ID:msg.Error:<-c.done", "sid:%v tid:%v wsURL:%v crashed:%t", s.id, s.targetID, c.wsURL, s.crashed) + return + } + } + c.sessionsMu.RUnlock() + c.emit("", &msg) + case msg.Method != "": c.logger.Debugf("Connection:recvLoop:msg.Method:emit", "sid:%v method:%q", msg.SessionID, msg.Method) ev, err := cdproto.UnmarshalMessage(&msg)