Skip to content
This repository has been archived by the owner on Feb 1, 2023. It is now read-only.

fix: fix a map access race condition in the want index #523

Merged
merged 1 commit into from
Jul 30, 2021
Merged

Conversation

Stebalien
Copy link
Member

We should have better tests here, but I'm not sure how to go about that. We basically need a fuzzer.

Copy link
Contributor

@aschmahmann aschmahmann left a comment

Choose a reason for hiding this comment

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

Seems reasonable. Is the problem here that we're calling e.peerLedger.CancelWant without taking the lock on the ledger?

Comment on lines 660 to 672
if hasLedger {
ledger.lk.RLock()
}
for _, k := range wl {
if hasLedger {
if _, has := ledger.WantListContains(k); has {
continue
}
}
e.peerLedger.CancelWant(p, k)
}
if hasLedger {
ledger.lk.RUnlock()
}
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: IMO it'd be easier to read this if we separated all the hasLedger pieces out and just had an if/else or an if + return.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah, good point.

Copy link
Member Author

Choose a reason for hiding this comment

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

Done

@Stebalien
Copy link
Member Author

Seems reasonable. Is the problem here that we're calling e.peerLedger.CancelWant without taking the lock on the ledger?

Yes. On the happy path we just read the map so we only need a read lock. On the sad path, we need to take the lock.

@Stebalien Stebalien merged commit 5c2c537 into master Jul 30, 2021
@Stebalien Stebalien deleted the fix/race branch July 30, 2021 20:10
@aschmahmann aschmahmann mentioned this pull request Aug 23, 2021
62 tasks
Jorropo pushed a commit to Jorropo/go-libipfs that referenced this pull request Jan 26, 2023
fix: fix a map access race condition in the want index

This commit was moved from ipfs/go-bitswap@5c2c537
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants