Skip to content

Commit

Permalink
Fixed so that only ctx.Done is nested
Browse files Browse the repository at this point in the history
  • Loading branch information
daisuke0925m committed Mar 18, 2024
1 parent 08031bc commit 50b50cf
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions db_go18.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,16 +53,17 @@ func (c *conn) beginTxOnce(ctx context.Context, done <-chan struct{}) (*sql.Tx,
}
go func() {
select {
case <-done:
// operation was successfully finished, so we don't close ctx on tx
case <-c.ctx.Done():
default:
case <-ctx.Done():
select {
case <-ctx.Done():
case <-done:
// the operation successfully finished at the "same time" as context cancellation, so we won't close ctx on tx
default:
// operation was interrupted by context cancel, so we cancel parent as well
c.cancel()
default:
}
case <-done:
// operation was successfully finished, so we don't close ctx on tx
case <-c.ctx.Done():
}
}()
return c.tx, nil
Expand Down

0 comments on commit 50b50cf

Please sign in to comment.