-
-
Notifications
You must be signed in to change notification settings - Fork 3k
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
core: add context.Context param to core.Resolve() #1189
Conversation
return r.resolveRecurse(0) | ||
} | ||
|
||
type resolver struct { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i just added this type to make the recursive call easier to grasp.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
@@ -89,7 +91,8 @@ Publish an <ipfs-path> to another public key (not implemented): | |||
} | |||
|
|||
// TODO n.Keychain.Get(name).PrivKey | |||
output, err := publish(n, n.PrivateKey, p) | |||
// TODO(cryptix): is req.Context().Context a child of n.Context()? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the top level context stuff around here is really confusing.. it uses this context group thing if i remember correctly
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@jbenet can you tell us?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
apparently req.Context().Context()
is not yet a child of n.Context()
: https://github.com/ipfs/go-ipfs/blob/master/commands/http/handler.go#L52-L54 -- it should be.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
and yes it's very confusing :(
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@jbenet ohai cmdlib 😞 .. but fixed 😄. Do I need to mirror this change on the offline mode, too?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do I need to mirror this change on the offline mode, too?
probably? i can think about this more carefully tomorrow.
1db73d8
to
72ee5d5
Compare
TODO(cryptix): we wrapped a new context for each name iteration | ||
is this correct? | ||
moved it out of the loop for now | ||
*/ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i think this used to be right. we should probably give longer names more time. example: if resolution takes ~10s per hop, 1min is not going to cut it for paths larger than 6. (resolution should be much faster, sure, but remember that resolution might go across the routing system).
in the end, this probably should come from the context coming in, and not have a timeout internally. (but in that case we must make sure all source calls do have proper timeouts
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That makes sense. Changed it back.
This PR is fighting the good fight :) 👍 Some notes (not for this PR, but for when making the core/shell) api:
[1] since contexts are pervasive and we'd like to be able to have them in many function calls, we'd like to be able to add them all over to expose the ability to cancel things. But this does pollute the API all over the place, and make it harder to glean for the first time user. One way is to have a package that mirrors the functions without the ctx, for use in examples, and very simple use cases, and so on: // (simplified)
// in the standard package
function Resolve(ctx context.Context, p path.Path) (*merkledag.Node, error) { ... }
// in a separate (simplifying) package
function Resolve(p path.Path) (*merkledag.Node, error) {
ctx, cancel := context.WithCancel(n.Context())
defer cancel()
return core.Resolve(ctx, p)
} |
I'm not a fan of expanding the surface area of our exported API. Ideally, we have as few top level functions as possible, to reduce the mental load on users |
6a9be55
to
274da9e
Compare
Addressed comments and rebased |
|
||
I assume it really isn't because ServeHTTP() doesn't take a pointer receiver, but it's really subtule.. | ||
|
||
Shouldn't the context be just put on the command request? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, this is super sketchy. I think its probably best to put the context into the request object instead of here on the handler context
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
well, it is put into the request object, but it's put here: line 104. maybe we can find another place to put it, earlier? (nbd for me -- i want to rewire how all this works already)
Looks good to me! its a bit cleaner now too, good job |
274da9e
to
44d47af
Compare
The problem is that many times the type system and many knobs to use are a mental load on users already. Understanding + using contexts correctly is certainly a very big one. And, it's a separate package, only there if you need it. It's not a bigger surface area on the same package-- it's tucked away. The functions aren't different-- it's a tweaked API for the same thing. Anyway, even if it doesn't go into go-ipfs, i'd make this a package and publish it somewhere. If modules are very simple, and stable-- more modules isn't bad. Bigger modules with lots of semantics are painful. |
This LGTM. |
Didn't pass on any osx-- dont seem related but running again just in case. |
44d47af
to
133fedd
Compare
commands/object: remove objectData() and objectLinks() helpers resolver: added context parameters sharness: $HASH carried the \r from the http protocol with sharness: write curl output to individual files http gw: break PUT handler until PR#1191
3791071
to
f640ba0
Compare
@cryptix 👏 👏 👏 👏 👏 👏 very clean PR! |
core: add context.Context param to core.Resolve()
Following the discussion of #1150, we need to be able to pass a context to core.Resolve() so that a user is able to stop it.