From 5c4fcaa5c17baf8e768fb6840dbd0626f20656ba Mon Sep 17 00:00:00 2001 From: Ziheng Liu Date: Sat, 3 Aug 2019 22:01:51 -0700 Subject: [PATCH] Change Unlock to defer Unlock, to avoid data race --- internal/transport/flowcontrol.go | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/internal/transport/flowcontrol.go b/internal/transport/flowcontrol.go index 5ea997a7e45b..f262edd8ecda 100644 --- a/internal/transport/flowcontrol.go +++ b/internal/transport/flowcontrol.go @@ -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)) @@ -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 }