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

use correct context for dht notifs #1568

Merged
merged 1 commit into from
Aug 17, 2015
Merged

use correct context for dht notifs #1568

merged 1 commit into from
Aug 17, 2015

Conversation

whyrusleeping
Copy link
Member

I was trying to diagnose some dht issues i was noticing and i noticed that some entries were absent from the output of the query notifications. It looks like i was relying on the context to be passed through to the query functions. but at some point the goprocess stuff got shoved in the middle of it, so now we derive a context from a process that is derived from a context and pass that to the queryFunc. I put a little closure in that allows us to have the correct context within the queryFuncs to properly publish events.

License: MIT
Signed-off-by: Jeromy [email protected]

License: MIT
Signed-off-by: Jeromy <[email protected]>
@jbenet jbenet added the status/in-progress In progress label Aug 12, 2015
@@ -40,9 +40,12 @@ func (dht *IpfsDHT) GetClosestPeers(ctx context.Context, key key.Key) (<-chan pe
peerset.Add(p)
}

// since the query doesnt actually pass our context down
// we have to hack this here. whyrusleeping isnt a huge fan of goprocess
Copy link
Member

Choose a reason for hiding this comment

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

since the query doesnt actually pass our context down

can you clarify what you mean? where / why doesnt it get passed down?

Copy link
Member Author

Choose a reason for hiding this comment

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

so, the context gets passed into run, and then we create a goprocess. We set that goprocess to be closed when the context gets cancelled, and then we derive a context from that process to pass to the queryFuncs. it seems a little redundant.

Copy link
Member

Choose a reason for hiding this comment

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

creating a process from a context, or a context from a process, is the same thing as deriving a new context from a parent context, or a process from a parent process. it looks a bit awkward because the models are a bit different, but it is the same idea. it's a process tree. it's just that the process can let you reason about teardown, whereas the context cant.

Copy link
Member

Choose a reason for hiding this comment

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

(meaning that likely the same thing would happen with the contexts -- the derivation of child contexts. the reason for using process there (instead of a bare context) is about rate limiting and proper teardown).

Copy link
Member

Choose a reason for hiding this comment

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

this still doesn't answer:

  • where / why doesnt it get passed down?

Copy link
Member Author

Choose a reason for hiding this comment

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

contexts have a Value field, which gives you a key value mapping that is tied to a particular chain of contexts. With the goprocess thing in the middle, those value requests dont get propagated up the chain like they would if we exclusively used contexts.

Copy link
Member

Choose a reason for hiding this comment

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

ohhhh: the PublishQueryEvent thing needs ctx.Value. yeah that sucks

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... i'm not sure of a 'right' way to do this. but its really nice to be able to use the context for that purpose, allows you to easily register for just the notifications that you are interested in

Copy link
Member

Choose a reason for hiding this comment

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

maybe we should have it in process too? (or go back to always-having-a-context-in-a-process and allow:

v := px.Context().Value(k)

@jbenet
Copy link
Member

jbenet commented Aug 17, 2015

I'll merge this for now, but should probably fix goprocess to not kill the value trees.

jbenet added a commit that referenced this pull request Aug 17, 2015
use correct context for dht notifs
@jbenet jbenet merged commit 49dab68 into master Aug 17, 2015
@jbenet jbenet removed the status/in-progress In progress label Aug 17, 2015
@jbenet jbenet deleted the fix/dht-commands branch August 17, 2015 02:38
@ajnavarro ajnavarro mentioned this pull request Aug 24, 2022
72 tasks
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.

2 participants