Skip to content

Commit

Permalink
Change Unlock to defer Unlock, to avoid data race (#2953)
Browse files Browse the repository at this point in the history
  • Loading branch information
lzhfromustc authored and easwars committed Aug 7, 2019
1 parent 1f154c6 commit cd5357d
Showing 1 changed file with 1 addition and 2 deletions.
3 changes: 1 addition & 2 deletions internal/transport/flowcontrol.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@ func (f *inFlow) maybeAdjust(n uint32) uint32 {
n = uint32(math.MaxInt32)
}
f.mu.Lock()
defer f.mu.Unlock()
// estSenderQuota is the receiver's view of the maximum number of bytes the sender
// can send without a window update.
estSenderQuota := int32(f.limit - (f.pendingData + f.pendingUpdate))
Expand All @@ -169,10 +170,8 @@ func (f *inFlow) maybeAdjust(n uint32) uint32 {
// is padded; We will fallback on the current available window(at least a 1/4th of the limit).
f.delta = n
}
f.mu.Unlock()
return f.delta
}
f.mu.Unlock()
return 0
}

Expand Down

0 comments on commit cd5357d

Please sign in to comment.