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

Remove goprocess #118

Closed
wants to merge 2 commits into from
Closed

Remove goprocess #118

wants to merge 2 commits into from

Conversation

hannahhoward
Copy link
Contributor

Goals

This change removes goprocess to reduce the learning curve for new people coming in to working on go-bitswap. While goprocess is a really cool library, it's non-standard, and it's partial implementation in go-bitswap, unique as I understand it to the IPFS codebase, increases confusion in the bitswap codebase. I remember losing at least a day to figuring out what it is and whether it should be there when I first started on go-bitswap. We're really not using it for anything special, other than to cancel some go routines, for which contexts are adequate.

We did have a broader conversation about go routine supervision in go-ipfs, but came to the conclusion that at least for the moment we're using just contexts.

Implementation

  • Remove go-process, replace with context cancellation code where neccesary.

@ghost ghost assigned hannahhoward May 10, 2019
@ghost ghost added the status/in-progress In progress label May 10, 2019
bitswap.go Outdated
@@ -357,7 +344,8 @@ func (bs *Bitswap) ReceiveError(err error) {

// Close is called to shutdown Bitswap
func (bs *Bitswap) Close() error {
return bs.process.Close()
bs.cancel()
Copy link
Member

Choose a reason for hiding this comment

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

Unfortunately, this won't wait for bitswap to stop, that's really why we use goprocess. However, we can do the "go" thing and use a waitgroup.

That is, every where we would have called process.Go(...), call:

bs.wg.Add(1)
go func() {
defer bs.wg.Done()
}()

(and then bs.wg.Wait() in Close()).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

make sense (though I wonder what else we should be waiting to close -- sessions, wantmanager, etc)

will add.

Copy link
Member

Choose a reason for hiding this comment

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

Ideally, we'd wait for all workers.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

So, you know, if we need both a context and a waitgroup, and we need to cover all our workers -- if waiting for shutdowns across the board is really something we should be doing -- I wonder if we should just keep goprocess? I notice you have some recent commits on the repo -- may be we just start maintaining it? Also are we using it elsewhere? Maybe libp2p?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Cause otherwise I'm gonna endup writing some code that looks like a mini-goprocess anyway.

Copy link
Member

Choose a reason for hiding this comment

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

I wonder if we should just keep goprocess?

I'd like to (a) switch to something simpler and (b) not leak it across abstraction boundaries.

And yes, we're also using it in go-libp2p.

(also, ipfs/kubo#5810 (comment))

Copy link
Contributor Author

Choose a reason for hiding this comment

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

see monitor/monitor.go

@Stebalien Stebalien changed the base branch from feat/improve-docs to master May 10, 2019 22:52
Go process was used only minimally, and is non-standard. None of the features we used went beyond
context. As such, remove it.
@hannahhoward hannahhoward force-pushed the feat/remove-go-process branch from 21a1906 to c80e868 Compare May 14, 2019 02:17
@hannahhoward
Copy link
Contributor Author

@Stebalien ok I built a little library to do this. The main goals were:

  1. Keep it small (1 file)
  2. Keep it flexible so it can be used without affecting API boundaries, and usable if we ever move off context as our main driver

The next step is to try applying it to the other long running routines in go-bitswap

see monitor/monitor.go

@Stebalien
Copy link
Member

Given that we're already using goprocess elsewhere, I'm not sure if it's worth introducing a new abstraction into bitswap like this. If we're going to introduce a new abstraction, I'd rather prototype it in separate package, thoroughly test the API against all current uses of goprocess (not a small task).

@hannahhoward
Copy link
Contributor Author

alright gonna close this PR for now.

I'm fine with prototyping something new -- but personally I feel like we need a clearer sense of our intent in a new package before we do it. I.e. what is wrong with go-process? Why can't we just improve it? Does it need to be better integrated with context?

@hannahhoward
Copy link
Contributor Author

anyway that discussion can happen on the main issue.

@whyrusleeping whyrusleeping removed the status/in-progress In progress label May 15, 2019
@Stebalien
Copy link
Member

but personally I feel like we need a clearer sense of our intent in a new package before we do it. I.e. what is wrong with go-process? Why can't we just improve it? Does it need to be better integrated with context?

Completely agree.

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.

3 participants