mirror of
https://github.com/pocket-id/pocket-id.git
synced 2026-03-22 17:55:08 +00:00
fix: better error messages when there's another instance of Pocket ID running (#1370)
This commit is contained in:
committed by
GitHub
parent
e3905cf315
commit
832b7fbff4
@@ -2,6 +2,7 @@ package bootstrap
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"log/slog"
|
"log/slog"
|
||||||
"time"
|
"time"
|
||||||
@@ -11,6 +12,7 @@ import (
|
|||||||
|
|
||||||
"github.com/pocket-id/pocket-id/backend/internal/common"
|
"github.com/pocket-id/pocket-id/backend/internal/common"
|
||||||
"github.com/pocket-id/pocket-id/backend/internal/job"
|
"github.com/pocket-id/pocket-id/backend/internal/job"
|
||||||
|
"github.com/pocket-id/pocket-id/backend/internal/service"
|
||||||
"github.com/pocket-id/pocket-id/backend/internal/storage"
|
"github.com/pocket-id/pocket-id/backend/internal/storage"
|
||||||
"github.com/pocket-id/pocket-id/backend/internal/utils"
|
"github.com/pocket-id/pocket-id/backend/internal/utils"
|
||||||
)
|
)
|
||||||
@@ -60,7 +62,9 @@ func Bootstrap(ctx context.Context) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
waitUntil, err := svc.appLockService.Acquire(ctx, false)
|
waitUntil, err := svc.appLockService.Acquire(ctx, false)
|
||||||
if err != nil {
|
if errors.Is(err, service.ErrLockUnavailable) {
|
||||||
|
return errors.New("it appears that there's already one instance of Pocket ID running; running multiple replicas of Pocket ID is currently not supported")
|
||||||
|
} else if err != nil {
|
||||||
return fmt.Errorf("failed to acquire application lock: %w", err)
|
return fmt.Errorf("failed to acquire application lock: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -119,11 +119,10 @@ func acquireImportLock(ctx context.Context, db *gorm.DB, force bool) error {
|
|||||||
defer cancel()
|
defer cancel()
|
||||||
|
|
||||||
waitUntil, err := appLockService.Acquire(opCtx, force)
|
waitUntil, err := appLockService.Acquire(opCtx, force)
|
||||||
if err != nil {
|
if errors.Is(err, service.ErrLockUnavailable) {
|
||||||
if errors.Is(err, service.ErrLockUnavailable) {
|
//nolint:staticcheck
|
||||||
//nolint:staticcheck
|
return errors.New("Pocket ID must be stopped before importing data; please stop the running instance or run with --forcefully-acquire-lock to terminate the other instance")
|
||||||
return errors.New("Pocket ID must be stopped before importing data; please stop the running instance or run with --forcefully-acquire-lock to terminate the other instance")
|
} else if err != nil {
|
||||||
}
|
|
||||||
return fmt.Errorf("failed to acquire application lock: %w", err)
|
return fmt.Errorf("failed to acquire application lock: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -96,7 +96,8 @@ func (s *AppLockService) Acquire(ctx context.Context, force bool) (waitUntil tim
|
|||||||
|
|
||||||
var prevLock lockValue
|
var prevLock lockValue
|
||||||
if prevLockRaw != "" {
|
if prevLockRaw != "" {
|
||||||
if err := prevLock.Unmarshal(prevLockRaw); err != nil {
|
err = prevLock.Unmarshal(prevLockRaw)
|
||||||
|
if err != nil {
|
||||||
return time.Time{}, fmt.Errorf("decode existing lock value: %w", err)
|
return time.Time{}, fmt.Errorf("decode existing lock value: %w", err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -142,7 +143,8 @@ func (s *AppLockService) Acquire(ctx context.Context, force bool) (waitUntil tim
|
|||||||
return time.Time{}, fmt.Errorf("lock acquisition failed: %w", res.Error)
|
return time.Time{}, fmt.Errorf("lock acquisition failed: %w", res.Error)
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := tx.Commit().Error; err != nil {
|
err = tx.Commit().Error
|
||||||
|
if err != nil {
|
||||||
return time.Time{}, fmt.Errorf("commit lock acquisition: %w", err)
|
return time.Time{}, fmt.Errorf("commit lock acquisition: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user