-
Notifications
You must be signed in to change notification settings - Fork 37
stop using goprocess to control teardown #278
Conversation
2f4278a
to
206a275
Compare
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.
❤️
@@ -293,16 +278,6 @@ func (s *Swarm) Peerstore() peerstore.Peerstore { | |||
return s.peers | |||
} | |||
|
|||
// Context returns the context of the swarm | |||
func (s *Swarm) Context() context.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.
For posterity: the user should control their own system's shutdown.
@@ -201,11 +191,6 @@ func (s *Swarm) teardown() error { | |||
return nil | |||
} | |||
|
|||
// Process returns the Process of the swarm | |||
func (s *Swarm) Process() goprocess.Process { | |||
return s.proc |
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.
For posterity: this was very difficult to use correctly because adding child processes raced with the process shutting down (leading to a panic if this process closed before the child was added).
Technically, it could be used correctly with AddChildNoWait
, but most callers would use AddCHild
and Go
(leading to panics on shutdown).
@@ -103,11 +102,14 @@ type Swarm struct { | |||
// `extra` interface{} parameter facilitates the future migration. Supported | |||
// elements are: | |||
// - connmgr.ConnectionGater | |||
func NewSwarm(ctx context.Context, local peer.ID, peers peerstore.Peerstore, bwc metrics.Reporter, extra ...interface{}) *Swarm { | |||
func NewSwarm(local peer.ID, peers peerstore.Peerstore, bwc metrics.Reporter, extra ...interface{}) *Swarm { |
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.
If we're breaking this interface anyways, let's consider using functional options. We can also do that in a followup patch.
Deferring merging until we've cut a new -core release. |
8c94164
to
7ad413c
Compare
7ad413c
to
6ff34de
Compare
Depends on libp2p/go-libp2p-core#212.
This PR:
Swarm.Process() goprocess.Process
Swarm.Context() context.Context
context.Context
fromNewSwarm
Annoyingly, this means that we can't attach the closing of the peerstore in the
testing
package any more:go-libp2p-swarm/testing/testing.go
Lines 118 to 120 in 29bd937
We therefore return a
network.Network
fromtesting.GenSwarm
, and close the peerstore inClose
. This change is responsible for 95% of the LOC changed in this PR.