mirror of
https://github.com/lightninglabs/loop.git
synced 2026-08-13 12:33:03 +02:00
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:
parent
8f831e85ae
commit
514c3f06ad
2 changed files with 18 additions and 4 deletions
|
|
@ -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()
|
||||
|
|
|
|||
|
|
@ -44,6 +44,7 @@ func view(config *Config, lisCfg *ListenerCfg) error {
|
|||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer assetClient.Close()
|
||||
}
|
||||
|
||||
swapClient, cleanup, err := getClient(
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue