Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

making the daemon shutdown quicker #1478

Merged
merged 1 commit into from
Jul 14, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions exchange/bitswap/wantmanager.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,8 @@ func (mq *msgQueue) runQueue(ctx context.Context) {
mq.doWork(ctx)
case <-mq.done:
return
case <-ctx.Done():
return
}
}
}
Expand Down
16 changes: 10 additions & 6 deletions p2p/host/basic/natmgr.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion p2p/net/swarm/swarm.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
Expand Down