mirror of
https://github.com/ipfs/kubo.git
synced 2025-06-24 14:08:13 +08:00
clean up after listeners on shutdown
This commit is contained in:
@ -81,6 +81,7 @@ type Swarm struct {
|
|||||||
connsLock sync.RWMutex
|
connsLock sync.RWMutex
|
||||||
|
|
||||||
local *peer.Peer
|
local *peer.Peer
|
||||||
|
listeners []net.Listener
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewSwarm constructs a Swarm, with a Chan.
|
// NewSwarm constructs a Swarm, with a Chan.
|
||||||
@ -126,6 +127,9 @@ func (s *Swarm) connListen(maddr *ma.Multiaddr) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// NOTE: this may require a lock around it later. currently, only run on setup
|
||||||
|
s.listeners = append(s.listeners, list)
|
||||||
|
|
||||||
// Accept and handle new connections on this listener until it errors
|
// Accept and handle new connections on this listener until it errors
|
||||||
go func() {
|
go func() {
|
||||||
for {
|
for {
|
||||||
@ -172,6 +176,10 @@ func (s *Swarm) Close() {
|
|||||||
}
|
}
|
||||||
s.Chan.Close <- true // fan out
|
s.Chan.Close <- true // fan out
|
||||||
s.Chan.Close <- true // listener
|
s.Chan.Close <- true // listener
|
||||||
|
|
||||||
|
for _,list := range s.listeners {
|
||||||
|
list.Close()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Dial connects to a peer.
|
// Dial connects to a peer.
|
||||||
|
Reference in New Issue
Block a user