Skip to content

Commit

Permalink
storage: fix data race in contentionQueue
Browse files Browse the repository at this point in the history
When a pusher would write a new intent, it would previously sent its own
*TxnMeta to the next pusher. However, it would also possibly mutate it
higher up the stack (for example combining multiple responses in
DistSender). Make a copy instead.

Release note: None
  • Loading branch information
tbg committed Sep 25, 2018
1 parent e3a93f2 commit 85d5ab6
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions pkg/storage/intent_resolver.go
Original file line number Diff line number Diff line change
Expand Up @@ -347,6 +347,13 @@ func (cq *contentionQueue) add(
// contended key (i.e. newWIErr != nil).
contended.setLastTxnMeta(nil)
}
if newIntentTxn != nil {
// Shallow copy the TxnMeta. After this request returns (i.e. now), we might
// mutate it (DistSender and such), but the receiver of the channel will read
// it.
newIntentTxnCopy := *newIntentTxn
newIntentTxn = &newIntentTxnCopy
}
curPusher.waitCh <- newIntentTxn
close(curPusher.waitCh)
cq.mu.Unlock()
Expand Down

0 comments on commit 85d5ab6

Please sign in to comment.