Skip to content

bitswap: fix a minor data race - #3036

Merged
whyrusleeping merged 1 commit into
masterfrom
fix/wlist-race
Aug 4, 2016
Merged

whyrusleeping merged 1 commit into
masterfrom
fix/wlist-race

Conversation

@whyrusleeping

Copy link
Copy Markdown
Member

race detector picked up a minor race condition, Since loop iteration reuses the same local variable, its not safe to take its address and use it concurrently. The fix is to rebind the variable into a controlled scope (creating a new variable) and taking the address of that to pass outwards.

License: MIT
Signed-off-by: Jeromy why@ipfs.io

@Kubuxu

Kubuxu commented Aug 4, 2016

Copy link
Copy Markdown
Member

LGTH, but it would be great to have this explanation either as commit message or a comment.

race detector picked up a minor race condition, Since loop iteration
reuses the same local variable, its not safe to take its address and use
it concurrently. The fix is to rebind the variable into a controlled
scope (creating a new variable) and taking the address of that to pass
outwards.

License: MIT
Signed-off-by: Jeromy <why@ipfs.io>
@whyrusleeping

Copy link
Copy Markdown
Member Author

@Kubuxu added more description to the commit message

@Kubuxu

Kubuxu commented Aug 4, 2016

Copy link
Copy Markdown
Member

Great, thank you. LGTM

@whyrusleeping
whyrusleeping merged commit 2a4560c into master Aug 4, 2016
@whyrusleeping
whyrusleeping deleted the fix/wlist-race branch August 4, 2016 10:46
case <-broadcastSignal.C: // resend unfulfilled wantlist keys
log.Event(ctx, "Bitswap.Rebroadcast.active")
for _, e := range bs.wm.wl.Entries() {
e := e

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add:

e := e // prevent data race

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants