Skip to content
This repository has been archived by the owner on Sep 2, 2024. It is now read-only.

Commit

Permalink
fix: remove any chance of being able to concurrently call start funct…
Browse files Browse the repository at this point in the history
…ion (#468)
  • Loading branch information
rolznz authored Jun 19, 2024
1 parent 118c687 commit dde558e
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
8 changes: 8 additions & 0 deletions api/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"net/http"
"net/url"
"strings"
"sync"
"time"

"github.com/sirupsen/logrus"
Expand Down Expand Up @@ -579,7 +580,14 @@ func (api *api) SetNextBackupReminder(backupReminderRequest *BackupReminderReque
return nil
}

var startMutex sync.Mutex

func (api *api) Start(startRequest *StartRequest) error {
if !startMutex.TryLock() {
// do not allow to start twice in case this is somehow called twice
return errors.New("app is already starting")
}
defer startMutex.Unlock()
return api.svc.StartApp(startRequest.UnlockPassword)
}

Expand Down
3 changes: 3 additions & 0 deletions service/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,9 @@ func (svc *service) StartNostr(ctx context.Context, encryptionKey string) error
}

func (svc *service) StartApp(encryptionKey string) error {
if svc.lnClient != nil {
return errors.New("app already started")
}
if !svc.cfg.CheckUnlockPassword(encryptionKey) {
logger.Logger.Errorf("Invalid password")
return errors.New("invalid password")
Expand Down

0 comments on commit dde558e

Please sign in to comment.