Skip to content

Commit

Permalink
sql: fix bug in close of ieSyncResultChannel
Browse files Browse the repository at this point in the history
When finishing sending on the ieSyncResultChannel we do not need to and should
not close the channel used to unblock the sender. Doing so can result in a
panic if the reader is concurrently trying to unblock the sender. We could
close that channel but there's no obvious reason to.

Fixes cockroachdb#62939

Release note: None
  • Loading branch information
ajwerner authored and yuzefovich committed Apr 9, 2021
1 parent e1a70d8 commit 22f902e
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion pkg/sql/internal_result_channel.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,11 @@ type syncIEResultChannel struct {
// goroutine exits its run() loop whereas waitCh is closed when closing the
// iterator.
dataCh chan ieIteratorResult

// waitCh is never closed. In all places where the caller may interact with it
// the doneCh is also used. This policy is in place to make it safe to unblock
// both the reader and the writer without any hazards of a blocked reader
// attempting to send on a closed channel.
waitCh chan struct{}

// doneCh is used to indicate that the ReadWriter has been closed.
Expand Down Expand Up @@ -195,7 +200,6 @@ func (i *syncIEResultChannel) unblockWriter(ctx context.Context) (done bool, err

func (i *syncIEResultChannel) finish() {
close(i.dataCh)
close(i.waitCh)
}

func (i *syncIEResultChannel) nextResult(
Expand Down

0 comments on commit 22f902e

Please sign in to comment.