Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: do not allow lnclient access while it is shutting down #605

Merged
merged 3 commits into from
Sep 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions api/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -427,6 +427,12 @@ func (api *api) ChangeUnlockPassword(changeUnlockPasswordRequest *ChangeUnlockPa
}

func (api *api) Stop() error {
if !startMutex.TryLock() {
// do not allow to stop twice in case this is somehow called twice
return errors.New("app is busy")
}
defer startMutex.Unlock()

logger.Logger.Info("Running Stop command")
if api.svc.GetLNClient() == nil {
return errors.New("LNClient not started")
Expand Down Expand Up @@ -719,7 +725,7 @@ func (api *api) Start(startRequest *StartRequest) {
func (api *api) StartInternal(startRequest *StartRequest) (err error) {
if !startMutex.TryLock() {
// do not allow to start twice in case this is somehow called twice
return errors.New("app is already starting")
return errors.New("app is busy")
}
defer startMutex.Unlock()
return api.svc.StartApp(startRequest.UnlockPassword)
Expand All @@ -728,7 +734,7 @@ func (api *api) StartInternal(startRequest *StartRequest) (err error) {
func (api *api) Setup(ctx context.Context, setupRequest *SetupRequest) error {
if !startMutex.TryLock() {
// do not allow to start twice in case this is somehow called twice
return errors.New("app is already starting")
return errors.New("app is busy")
}
defer startMutex.Unlock()
info, err := api.GetInfo(ctx)
Expand Down
6 changes: 4 additions & 2 deletions service/stop.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,11 @@ func (svc *service) stopLNClient() {
if svc.lnClient == nil {
return
}
lnClient := svc.lnClient
svc.lnClient = nil

logger.Logger.Info("Shutting down LN client")
err := svc.lnClient.Shutdown()
err := lnClient.Shutdown()
if err != nil {
logger.Logger.WithError(err).Error("Failed to stop LN client")
svc.eventPublisher.Publish(&events.Event{
Expand All @@ -34,7 +37,6 @@ func (svc *service) stopLNClient() {
return
}
logger.Logger.Info("Publishing node shutdown event")
svc.lnClient = nil
svc.eventPublisher.Publish(&events.Event{
Event: "nwc_node_stopped",
})
Expand Down
Loading