mirror of
https://github.com/ipfs/kubo.git
synced 2025-07-01 02:30:39 +08:00
making the daemon shutdown quicker
License: MIT Signed-off-by: Jeromy <jeromyj@gmail.com>
This commit is contained in:
@ -140,6 +140,8 @@ func (mq *msgQueue) runQueue(ctx context.Context) {
|
|||||||
mq.doWork(ctx)
|
mq.doWork(ctx)
|
||||||
case <-mq.done:
|
case <-mq.done:
|
||||||
return
|
return
|
||||||
|
case <-ctx.Done():
|
||||||
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -75,18 +75,22 @@ func (nmgr *natManager) discoverNAT() {
|
|||||||
// to avoid leaking resources in a non-obvious way. the only case
|
// to avoid leaking resources in a non-obvious way. the only case
|
||||||
// this affects is when the daemon is being started up and _immediately_
|
// 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.
|
// asked to close. other services are also starting up, so ok to wait.
|
||||||
nat := inat.DiscoverNAT()
|
discoverdone := make(chan struct{})
|
||||||
if nat == nil { // no nat, or failed to get it.
|
var nat *inat.NAT
|
||||||
return
|
go func() {
|
||||||
}
|
defer close(discoverdone)
|
||||||
|
nat = inat.DiscoverNAT()
|
||||||
|
}()
|
||||||
|
|
||||||
// by this point -- after finding the NAT -- we may have already
|
// by this point -- after finding the NAT -- we may have already
|
||||||
// be closing. if so, just exit.
|
// be closing. if so, just exit.
|
||||||
select {
|
select {
|
||||||
case <-worker.Closing():
|
case <-worker.Closing():
|
||||||
nat.Close()
|
|
||||||
return
|
return
|
||||||
default:
|
case <-discoverdone:
|
||||||
|
if nat == nil { // no nat, or failed to get it.
|
||||||
|
return
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// wire up the nat to close when nmgr closes.
|
// wire up the nat to close when nmgr closes.
|
||||||
|
@ -187,7 +187,7 @@ func (s *Swarm) NewStreamWithPeer(p peer.ID) (*Stream, error) {
|
|||||||
// if we have no connections, try connecting.
|
// if we have no connections, try connecting.
|
||||||
if len(s.ConnectionsToPeer(p)) == 0 {
|
if len(s.ConnectionsToPeer(p)) == 0 {
|
||||||
log.Debug("Swarm: NewStreamWithPeer no connections. Attempting to connect...")
|
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
|
return nil, err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user