loopd: close tapd client connections

Close the TapdClient when daemon initialization fails, during normal
shutdown, and after the view command completes. This prevents gRPC
transport resources from leaking across embedded daemon lifecycles and
error paths.
This commit is contained in:
Slyghtning 2026-07-31 21:16:37 +02:00
parent 8f831e85ae
commit 514c3f06ad
No known key found for this signature in database
GPG key ID: F82D456EA023C9BF
2 changed files with 18 additions and 4 deletions

View file

@ -158,6 +158,15 @@ func (d *Daemon) Start() error {
if err != nil {
return err
}
defer func() {
if err == nil || d.assetClient == nil {
return
}
d.assetClient.Close()
d.assetClient = nil
}()
}
// With lnd connected, initialize everything else, such as the swap
@ -178,15 +187,15 @@ func (d *Daemon) Start() error {
// If we get here, we already have started several goroutines. So if
// anything goes wrong now, we need to cleanly shut down again.
startErr := d.startWebServers()
if startErr != nil {
errorf("Error while starting daemon: %v", startErr)
err = d.startWebServers()
if err != nil {
errorf("Error while starting daemon: %v", err)
d.Stop()
stopErr := <-d.ErrChan
if stopErr != nil {
errorf("Error while stopping daemon: %v", stopErr)
}
return startErr
return err
}
return nil
@ -1145,6 +1154,10 @@ func (d *Daemon) stop() {
if d.clientCleanup != nil {
d.clientCleanup()
}
if d.assetClient != nil {
d.assetClient.Close()
d.assetClient = nil
}
// Everything should be shutting down now, wait for completion.
d.wg.Wait()

View file

@ -44,6 +44,7 @@ func view(config *Config, lisCfg *ListenerCfg) error {
if err != nil {
return err
}
defer assetClient.Close()
}
swapClient, cleanup, err := getClient(