Skip to content
This repository was archived by the owner on Jan 30, 2025. It is now read-only.

Commit 7b35e83

Browse files
ankur22ka3de
authored andcommitted
Add a msgId type that will help create unique ids
Currently the msgIds clash from one session to another as well as with messages that are sent without a session on the connection event loop. Generally this isn't an issue, but recently we have found that chrome sometimes returns an error without the sessionId that was in the original request msg. When this occurs, we route those error responses to handlers that are waiting on the connection event loop. If there's a clash in msgId then the wrong handler will work with the wrong response, which could result in incorrect behaviour. This change will enforce a unique msgId at the connection level, which should avoid such scenarios.
1 parent dc0152b commit 7b35e83

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

common/connection.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,19 @@ const wsWriteBufferSize = 1 << 20
2828
var _ EventEmitter = &Connection{}
2929
var _ cdp.Executor = &Connection{}
3030

31+
// Each connection needs its own msgID. A msgID will be used by the
32+
// connection and associated sessions. When a CDP request is made to
33+
// chrome, it's best to work with unique ids to avoid the Execute
34+
// handlers working with the wrong response, or handlers deadlocking
35+
// when their response is rerouted to the wrong handler.
36+
type msgID struct {
37+
id int64
38+
}
39+
40+
func (m *msgID) new() int64 {
41+
return atomic.AddInt64(&m.id, 1)
42+
}
43+
3144
type executorEmitter interface {
3245
cdp.Executor
3346
EventEmitter

0 commit comments

Comments
 (0)