internal/jsonrpc2_v2: fix a racy map assignment in readIncoming
If a call request comes it at the same time that a response becomes ready for another call (either via an explicit Respond call or the return from a Handle call), the map read and deletion for the response could race with the map assignment for the new (incoming) call. Change-Id: Ifd81dbc490486251e81c7eeae438806356f514af Reviewed-on: https://go-review.googlesource.com/c/tools/+/388595 Trust: Bryan Mills <bcmills@google.com> Run-TryBot: Bryan Mills <bcmills@google.com> Reviewed-by: Ian Cottrell <iancottrell@google.com> gopls-CI: kokoro <noreply+kokoro@google.com> TryBot-Result: Gopher Robot <gobot@golang.org>
This commit is contained in:
parent
87c9a8057e
commit
13320502f5
2 changed files with 9 additions and 1 deletions
|
|
@ -322,8 +322,8 @@ func (c *Connection) readIncoming(ctx context.Context, reader Reader, toQueue ch
|
||||||
// cancelled by id
|
// cancelled by id
|
||||||
if msg.IsCall() {
|
if msg.IsCall() {
|
||||||
pending := <-c.incomingBox
|
pending := <-c.incomingBox
|
||||||
c.incomingBox <- pending
|
|
||||||
pending[msg.ID] = entry
|
pending[msg.ID] = entry
|
||||||
|
c.incomingBox <- pending
|
||||||
}
|
}
|
||||||
// send the message to the incoming queue
|
// send the message to the incoming queue
|
||||||
toQueue <- entry
|
toQueue <- entry
|
||||||
|
|
|
||||||
|
|
@ -60,6 +60,14 @@ var callTests = []invoker{
|
||||||
notify{"unblock", "a"},
|
notify{"unblock", "a"},
|
||||||
collect{"a", true, false},
|
collect{"a", true, false},
|
||||||
}},
|
}},
|
||||||
|
sequence{"concurrent", []invoker{
|
||||||
|
async{"a", "fork", "a"},
|
||||||
|
notify{"unblock", "a"},
|
||||||
|
async{"b", "fork", "b"},
|
||||||
|
notify{"unblock", "b"},
|
||||||
|
collect{"a", true, false},
|
||||||
|
collect{"b", true, false},
|
||||||
|
}},
|
||||||
}
|
}
|
||||||
|
|
||||||
type binder struct {
|
type binder struct {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue