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

Cleanup ctxgroup goprocess #1385

Merged
merged 6 commits into from
Jul 5, 2015
Merged

Conversation

rht
Copy link
Contributor

@rht rht commented Jun 17, 2015

Close #1030

Pending waiting for goprocess to have SetTeardown()

@jbenet jbenet added the backlog label Jun 17, 2015
@rht rht force-pushed the cleanup-ctxgroup-goprocess branch 2 times, most recently from 0c080cd to ef921b4 Compare June 17, 2015 16:03
@@ -104,7 +105,7 @@ type IpfsNode struct {

IpnsFs *ipnsfs.Filesystem

ctxgroup.ContextGroup
goprocess.Process
Copy link
Member

Choose a reason for hiding this comment

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

what i've been doing with goprocess is to make this a variable, not embedded type:

type Object struct {
  proc goprocess.Process
}

And then have a function that returns the process.

func (o Object) Process() goprocess.Process {
  return o.proc
}

the reason is that the Process interface is pretty large and embedding it dumps a bunch of objects on the user. maybe move to that? sorry for not describing it earlier.

@jbenet
Copy link
Member

jbenet commented Jun 17, 2015

I'll wait till the SetTeardown and WithContextAndTeardown are in before CRing more. there may be other races to fix.

@rht
Copy link
Contributor Author

rht commented Jun 18, 2015

How to godep update github.com/jbenet/goprocess? It errs "cannot find package x in any of $GOROOT, $GOPATH".

@jbenet
Copy link
Member

jbenet commented Jun 18, 2015

@rht I updated it in #1392 should be able to just rebase on top

@rht
Copy link
Contributor Author

rht commented Jun 18, 2015

Still want to know how it was done.

@rht rht force-pushed the cleanup-ctxgroup-goprocess branch from ef921b4 to dfa843c Compare June 18, 2015 12:24
@jbenet
Copy link
Member

jbenet commented Jun 18, 2015

@rht this is a typical flow.

# first, make sure my github.com/jbenet/goprocess dir is up to date
go get -u github.com/jbenet/goprocess
# or if that fails (dirty working dir or something):
cd ~/go/src/github.com/jbenet/goprocess && git fetch 

# tell godep to update github.com/jbenet/goprocess
cd ~/go/src/github.com/ipfs/go-ipfs
godep update github.com/jbenet/goprocess

# if godep errors with "cannot build package X" it usually means i don't
# have the version needed locally. One can try using `godep restore`
# but i like minimizing what godep touches, so i usually just update them manually:
go get -u github.com/jbenet/go-random
go get -u github.com/chriscool/go-sleep
...

# godep update should work now.
godep update github.com/jbenet/goprocess

# after updating, run `make vendor` to rewrite paths, if any have changed.
make vendor

# this _may_ remove godeps accidentally that shouldnt be removed. just dont
# commit those deletions, and just `git checkout Godeps/_workspace/...` them back

# selectively add only the bits we want:
# the vendored dir, and the updated line for the repo in the Godeps.json
git add -p Godeps/

@rht
Copy link
Contributor Author

rht commented Jun 18, 2015

Thanks for writing that. It is ... very detailed and thorough.
(Though I doubt it will be rediscovered in google and will just stay in this corner of github)

i c so it is godep restore to nuke my problem, or:

go get -u github.com/jbenet/go-random
go get -u github.com/chriscool/go-sleep
...

If there is out-of-box way to go get each of the Godeps.json without that '...' (I mean one can just use jq/sed, but ...)

To sum up my surprise: why isn't godep already reading the $PWD/Godeps/_workspace in the first place (that it itself creates) in addition to $GOPATH and $GOROOT? Which it could have.

update: works now.

@rht rht force-pushed the cleanup-ctxgroup-goprocess branch 6 times, most recently from d63cc0d to 7dffde7 Compare June 20, 2015 08:51
@rht
Copy link
Contributor Author

rht commented Jun 20, 2015

@jbenet rebased and added Process() method, except for IpfsNode where it requires the process to be assigned externally.

@jbenet
Copy link
Member

jbenet commented Jun 20, 2015

except for IpfsNode where it requires the process to be assigned externally.

what's the requirement? if lots of things call Close, so we can write a simple method like:

func (node *IpfsNode) Close() error {
  return node.proc.Close()
}

or something

@rht rht force-pushed the cleanup-ctxgroup-goprocess branch 5 times, most recently from 19d1744 to 6d27119 Compare June 21, 2015 08:52
@rht
Copy link
Contributor Author

rht commented Jun 21, 2015

@jbenet fixed. SetTeardown can't just be glued to WithContext due to the special cases here.

@jbenet
Copy link
Member

jbenet commented Jun 22, 2015

SetTeardown can't just be glued to WithContext due to the special cases here.

?

@rht i still think this is unsafe. it's a race that was there earlier.

Maybe this can fix it:

proc := goprocess.WithTeardown(node.teardown)
goprocessctx.WaitForContext(ctx, proc)

or maybe can make a function in https://github.com/jbenet/goprocess/blob/master/context/context.go like:

func WithContextAndTeardown(ctx context.Context, tf goprocess.TeardownFunc) goprocess.Process {
  if ctx == nil {
    panic("nil Context")
  }
  p := goprocess.WithTeardown(tf)
  go func() {
    <-ctx.Done()
    p.Close()
  }()
  return p
}

@rht
Copy link
Contributor Author

rht commented Jun 22, 2015

Then is it likely that any code using SetTeardown is unsafe?

@jbenet
Copy link
Member

jbenet commented Jun 22, 2015

For processes that spawn from a context or parent processes yes. (Which I guess is most cases where SetTeardown would be called).

We could actually fix this with a hack that may be semantically ok: if SetTeardown is called after the process is called, immediately call The teardown function. (Calling SetTeardown twice could be defined to be an error).


Sent from Mailbox

On Mon, Jun 22, 2015 at 3:23 AM, rht notifications@github.com wrote:

Then is it likely that any code using SetTeardown is unsafe?

Reply to this email directly or view it on GitHub:
#1385 (comment)

@rht
Copy link
Contributor Author

rht commented Jun 26, 2015

@rht rht force-pushed the cleanup-ctxgroup-goprocess branch from 361be7c to 2f13ac2 Compare June 26, 2015 04:08
@jbenet
Copy link
Member

jbenet commented Jun 26, 2015

@rht

Hasn't this been done in https://github.com/jbenet/goprocess/blob/master/impl-mutex.go#L199 already?

i think that doesn't clear the parent's ptr to the processLink, so the processLink remains allocated.

@jbenet
Copy link
Member

jbenet commented Jun 26, 2015

@rht +1 to all the golint / go vet changes. But hard to CR this with them in. could we separate those out into another PR and merge it first? (way easier to CR either of these in isolation + merge)

@rht rht force-pushed the cleanup-ctxgroup-goprocess branch from 2f13ac2 to 93ac8fb Compare June 26, 2015 09:25
@rht
Copy link
Contributor Author

rht commented Jun 26, 2015

i think that doesn't clear the parent's ptr to the processLink, so the processLink remains allocated.

I c, so what needs to be done is when the parent calls ClearChild() (https://github.com/jbenet/goprocess/blob/master/link.go#L72), it has to also unlink the child from the waitfors array.

@whyrusleeping whyrusleeping mentioned this pull request Jul 1, 2015
44 tasks
rht added 3 commits July 4, 2015 22:48
License: MIT
Signed-off-by: rht <rhtbot@gmail.com>
License: MIT
Signed-off-by: rht <rhtbot@gmail.com>
License: MIT
Signed-off-by: rht <rhtbot@gmail.com>
@rht rht force-pushed the cleanup-ctxgroup-goprocess branch 3 times, most recently from f7b7226 to 4c74119 Compare July 4, 2015 18:47
@rht
Copy link
Contributor Author

rht commented Jul 4, 2015

RFM.

This will be for a separate PR:

not necessarily, we just need to have a way to tell our parent we are dead, so that our parent removes the link.

A processLink itself should be removed whenever a ClearChild() or ParentClear() is called (actually this should just be Clear()).

Identity: config.Identity{
PeerID: p.String(),
},
}
Copy link
Member

Choose a reason for hiding this comment

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

i think this is right, but @whyrusleeping can you check too?

@jbenet
Copy link
Member

jbenet commented Jul 4, 2015

Hey @rht solid progress. almost there! I found another problem: #1385 (comment) that's my fault for not making CloseAfterContext() a func earlier. (which now makes it clear what's going on -- i.e. the word Close... appears there, so the safety concerns are raised.

@jbenet
Copy link
Member

jbenet commented Jul 4, 2015

Also, make sure you rebase on latest master (haven't checked if this is rebased or not, just have merged many things recently)

rht added 3 commits July 5, 2015 09:18
License: MIT
Signed-off-by: rht <rhtbot@gmail.com>
License: MIT
Signed-off-by: rht <rhtbot@gmail.com>
License: MIT
Signed-off-by: rht <rhtbot@gmail.com>
@rht rht force-pushed the cleanup-ctxgroup-goprocess branch from 4c74119 to 3daf749 Compare July 5, 2015 02:36
@rht
Copy link
Contributor Author

rht commented Jul 5, 2015

Also replaced anything with regex <-ctx.Done()\n.*close with CloseAfterContext.

@jbenet
Copy link
Member

jbenet commented Jul 5, 2015

this LGTM. merging, thanks @rht !

jbenet added a commit that referenced this pull request Jul 5, 2015
@jbenet jbenet merged commit 4c55b30 into ipfs:master Jul 5, 2015
@jbenet jbenet removed the backlog label Jul 5, 2015
@rht rht deleted the cleanup-ctxgroup-goprocess branch July 14, 2015 05:06
hacdias pushed a commit to ipfs/boxo that referenced this pull request Jan 27, 2023
 Cleanup ctxgroup goprocess

This commit was moved from ipfs/kubo@4c55b30
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