diff --git a/daemon.go b/daemon.go index 6fc5e54..1a09541 100644 --- a/daemon.go +++ b/daemon.go @@ -148,17 +148,8 @@ func (d *Daemon) listen() { } } -func (d *Daemon) Close() error { - if err := d.host.Close(); err != nil { - return err - } - - listenMaddr := d.listener.Multiaddr() - if err := d.listener.Close(); err != nil { - return err - } - - for _, subMaddr := range ma.Split(listenMaddr) { +func clearUnixSockets(maddr ma.Multiaddr) error { + for _, subMaddr := range ma.Split(maddr) { if subMaddr.Protocols()[0].Code == ma.P_UNIX { socket, err := subMaddr.ValueForProtocol(ma.P_UNIX) if err != nil { @@ -169,6 +160,28 @@ func (d *Daemon) Close() error { } } } + return nil +} + +func (d *Daemon) Close() error { + if err := d.host.Close(); err != nil { + return err + } + + listenMaddr := d.listener.Multiaddr() + if err := d.listener.Close(); err != nil { + return err + } + + for _, maddr := range d.handlers { + if err := clearUnixSockets(maddr); err != nil { + return err + } + } + + if err := clearUnixSockets(listenMaddr); err != nil { + return err + } return nil }