mirror of
https://github.com/ipfs/kubo.git
synced 2025-09-10 05:52:20 +08:00
bitswap/workers: fix proc / ctx wiring
This commit changes the order of the proc/ctx wiring, to ensure that the proc has been setup correctly before exiting. License: MIT Signed-off-by: Juan Batiz-Benet <juan@benet.ai>
This commit is contained in:
@ -9,6 +9,7 @@ import (
|
||||
"time"
|
||||
|
||||
process "github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/jbenet/goprocess"
|
||||
procctx "github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/jbenet/goprocess/context"
|
||||
context "github.com/ipfs/go-ipfs/Godeps/_workspace/src/golang.org/x/net/context"
|
||||
blocks "github.com/ipfs/go-ipfs/blocks"
|
||||
blockstore "github.com/ipfs/go-ipfs/blocks/blockstore"
|
||||
@ -68,15 +69,6 @@ func New(parent context.Context, p peer.ID, network bsnet.BitSwapNetwork,
|
||||
return nil
|
||||
})
|
||||
|
||||
go func() {
|
||||
<-px.Closing() // process closes first
|
||||
cancelFunc()
|
||||
}()
|
||||
go func() {
|
||||
<-ctx.Done() // parent cancelled first
|
||||
px.Close()
|
||||
}()
|
||||
|
||||
bs := &Bitswap{
|
||||
self: p,
|
||||
blockstore: bstore,
|
||||
@ -94,6 +86,15 @@ func New(parent context.Context, p peer.ID, network bsnet.BitSwapNetwork,
|
||||
|
||||
// Start up bitswaps async worker routines
|
||||
bs.startWorkers(px, ctx)
|
||||
|
||||
// bind the context and process.
|
||||
// do it over here to avoid closing before all setup is done.
|
||||
go func() {
|
||||
<-px.Closing() // process closes first
|
||||
cancelFunc()
|
||||
}()
|
||||
procctx.CloseAfterContext(px, ctx) // parent cancelled first
|
||||
|
||||
return bs
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user