1
0
mirror of https://github.com/ipfs/kubo.git synced 2025-06-29 09:34:03 +08:00

Merge pull request #1478 from ipfs/fix/slow-stop

making the daemon shutdown quicker
This commit is contained in:
Juan Batiz-Benet
2015-07-14 15:55:07 -07:00
3 changed files with 13 additions and 7 deletions

View File

@ -140,6 +140,8 @@ func (mq *msgQueue) runQueue(ctx context.Context) {
mq.doWork(ctx)
case <-mq.done:
return
case <-ctx.Done():
return
}
}
}

View File

@ -75,18 +75,22 @@ func (nmgr *natManager) discoverNAT() {
// to avoid leaking resources in a non-obvious way. the only case
// this affects is when the daemon is being started up and _immediately_
// asked to close. other services are also starting up, so ok to wait.
nat := inat.DiscoverNAT()
if nat == nil { // no nat, or failed to get it.
return
}
discoverdone := make(chan struct{})
var nat *inat.NAT
go func() {
defer close(discoverdone)
nat = inat.DiscoverNAT()
}()
// by this point -- after finding the NAT -- we may have already
// be closing. if so, just exit.
select {
case <-worker.Closing():
nat.Close()
return
default:
case <-discoverdone:
if nat == nil { // no nat, or failed to get it.
return
}
}
// wire up the nat to close when nmgr closes.

View File

@ -187,7 +187,7 @@ func (s *Swarm) NewStreamWithPeer(p peer.ID) (*Stream, error) {
// if we have no connections, try connecting.
if len(s.ConnectionsToPeer(p)) == 0 {
log.Debug("Swarm: NewStreamWithPeer no connections. Attempting to connect...")
if _, err := s.Dial(context.Background(), p); err != nil {
if _, err := s.Dial(s.Context(), p); err != nil {
return nil, err
}
}