Skip to content

Commit 191ac62

Browse files
committedJul 14, 2015
making the daemon shutdown quicker
License: MIT Signed-off-by: Jeromy <jeromyj@gmail.com>
1 parent 498e927 commit 191ac62

File tree

3 files changed

+13
-7
lines changed

3 files changed

+13
-7
lines changed
 

‎exchange/bitswap/wantmanager.go

+2
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,8 @@ func (mq *msgQueue) runQueue(ctx context.Context) {
140140
mq.doWork(ctx)
141141
case <-mq.done:
142142
return
143+
case <-ctx.Done():
144+
return
143145
}
144146
}
145147
}

‎p2p/host/basic/natmgr.go

+10-6
Original file line numberDiff line numberDiff line change
@@ -75,18 +75,22 @@ func (nmgr *natManager) discoverNAT() {
7575
// to avoid leaking resources in a non-obvious way. the only case
7676
// this affects is when the daemon is being started up and _immediately_
7777
// asked to close. other services are also starting up, so ok to wait.
78-
nat := inat.DiscoverNAT()
79-
if nat == nil { // no nat, or failed to get it.
80-
return
81-
}
78+
discoverdone := make(chan struct{})
79+
var nat *inat.NAT
80+
go func() {
81+
defer close(discoverdone)
82+
nat = inat.DiscoverNAT()
83+
}()
8284

8385
// by this point -- after finding the NAT -- we may have already
8486
// be closing. if so, just exit.
8587
select {
8688
case <-worker.Closing():
87-
nat.Close()
8889
return
89-
default:
90+
case <-discoverdone:
91+
if nat == nil { // no nat, or failed to get it.
92+
return
93+
}
9094
}
9195

9296
// wire up the nat to close when nmgr closes.

‎p2p/net/swarm/swarm.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ func (s *Swarm) NewStreamWithPeer(p peer.ID) (*Stream, error) {
187187
// if we have no connections, try connecting.
188188
if len(s.ConnectionsToPeer(p)) == 0 {
189189
log.Debug("Swarm: NewStreamWithPeer no connections. Attempting to connect...")
190-
if _, err := s.Dial(context.Background(), p); err != nil {
190+
if _, err := s.Dial(s.Context(), p); err != nil {
191191
return nil, err
192192
}
193193
}

0 commit comments

Comments
 (0)
Please sign in to comment.