Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
Menu
Open sidebar
adam.huang
go-libp2p
Commits
aae565ae
Commit
aae565ae
authored
Jul 14, 2015
by
Jeromy
Browse files
making the daemon shutdown quicker
License: MIT Signed-off-by:
Jeromy
<
jeromyj@gmail.com
>
parent
5140ff6b
Changes
2
Hide whitespace changes
Inline
Side-by-side
host/basic/natmgr.go
View file @
aae565ae
...
...
@@ -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.
...
...
net/swarm/swarm.go
View file @
aae565ae
...
...
@@ -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
(
c
ontext
.
Background
(),
p
);
err
!=
nil
{
if
_
,
err
:=
s
.
Dial
(
s
.
C
ontext
(),
p
);
err
!=
nil
{
return
nil
,
err
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment