Skip to content

Commit 812fb95

Browse files
authored
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.
1 parent 612e67a commit 812fb95

File tree

1 file changed

+2
-3
lines changed

1 file changed

+2
-3
lines changed

enterprise/tailnet/connio.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -197,9 +197,8 @@ func (c *connIO) UniqueID() uuid.UUID {
197197
func (c *connIO) Enqueue(resp *proto.CoordinateResponse) error {
198198
atomic.StoreInt64(&c.lastWrite, time.Now().Unix())
199199
c.mu.Lock()
200-
closed := c.closed
201-
c.mu.Unlock()
202-
if closed {
200+
defer c.mu.Unlock()
201+
if c.closed {
203202
return xerrors.New("connIO closed")
204203
}
205204
select {

0 commit comments

Comments
 (0)