Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add blocks to the blockstore before returning them from blockservice sessions. #4169

Merged
merged 1 commit into from
Aug 25, 2017

Conversation

Stebalien
Copy link
Member

fixes #4062 (yay!)

License: MIT
Signed-off-by: Steven Allen steven@stebalien.com

…sessions.

fixes #4062 (yay!)

License: MIT
Signed-off-by: Steven Allen <steven@stebalien.com>
k := blk.Cid()
ks := []*cid.Cid{k}
for _, s := range bs.SessionsForBlock(k) {
s.receiveBlockFrom(from, blk)
Copy link
Member

Choose a reason for hiding this comment

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

hrm... the change from "" to from here is on purpose? Whats the reasoning? ( i dont remember all the implications without my coffee)

Copy link
Member Author

Choose a reason for hiding this comment

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

I merged two functions. from will be "" when the user calls HasBlock but will be the peer from which we received the block when called from within bitswap.

Basically, we had two functions, HasBlock and a go routine inside ReceiveMessage where:

  1. The second function would:
  2. Notify all interested sessions that we had received the block.
  3. Remove the block from sessoins' wantlists.
  4. Call the first function which would:
  5. Put the block in the blockstore.
  6. Publish a notification on bs.notifications.
  7. Notify the session that we received the block (again) but claiming to have received it from "". This was to prevent a race condition where we'd notify the session that we received the block before putting it in the blockstore and then someone would try to get the block from the blockstore, not find it, and ask bitswap for it. I believe we should also have removed this block from the session but I'm not sure why we didn't (the new code does).
  8. Record the block in the bitswap engine.
  9. Reprovide the block.

I got rid of the first function, moved step 3 into step 7, and made it notify the session with the correct peer in step 7 if we received the block from the network.


The bug was that race condition in step 7. The fix works iff you keep the same bitswap instance but, if you replace the bitswap instance with a new one, the caller will not find the block in the blockstore and ask the new bitswap instance for the block (which doesn't know about it).

Copy link
Member

Choose a reason for hiding this comment

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

okay, that sounds good. Any way you could write a test?

Copy link
Member Author

Choose a reason for hiding this comment

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

TestFetchGraph? 😄 It's a bit hard to test a race condition...

Copy link
Member Author

Choose a reason for hiding this comment

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

(this is fixing a test failure so there is, by definition, a test case).

Copy link
Member

Choose a reason for hiding this comment

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

okay fineeee

@whyrusleeping whyrusleeping merged commit ab9b736 into master Aug 25, 2017
@whyrusleeping whyrusleeping deleted the fix/4062 branch August 25, 2017 19:07
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.

TestFetchGraph failing randomly
2 participants