fix: prevent connIO from panicking in race between Close and Enqueue (#10948)

Spotted during a code read.  ConnIO unlocks the mutex before attempting to write to the response channel, which could allow another goroutine to call Close() and close the channel, causing a panic.

Fix is to hold the mutex.  This won't cause a deadlock because the `select{}` has a `default` case, so we won't block even if the receiver isn't keeping up.
This commit is contained in:
Spike Curtis
2023-12-01 10:23:29 +04:00
committed by GitHub
parent 612e67a53b
commit 812fb95273
+2 -3
View File
@@ -197,9 +197,8 @@ func (c *connIO) UniqueID() uuid.UUID {
func (c *connIO) Enqueue(resp *proto.CoordinateResponse) error {
atomic.StoreInt64(&c.lastWrite, time.Now().Unix())
c.mu.Lock()
closed := c.closed
c.mu.Unlock()
if closed {
defer c.mu.Unlock()
if c.closed {
return xerrors.New("connIO closed")
}
select {