From 451f75b2a4a34972f9da5847c9630ca3796a6f91 Mon Sep 17 00:00:00 2001 From: Anderson Queiroz Date: Wed, 30 Nov 2022 13:59:03 +0100 Subject: [PATCH] Improve error for "instance lock is already locked" (#33788) --- CHANGELOG-developer.next.asciidoc | 1 + libbeat/cmd/instance/locks/lock.go | 4 ++-- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/CHANGELOG-developer.next.asciidoc b/CHANGELOG-developer.next.asciidoc index 10f3de4397e6..f96664f7233b 100644 --- a/CHANGELOG-developer.next.asciidoc +++ b/CHANGELOG-developer.next.asciidoc @@ -148,6 +148,7 @@ The list below covers the major changes between 7.0.0-rc2 and main only. - Add support for multiple regions in GCP {pull}32964[32964] - Use `T.TempDir` to create temporary test directory {pull}33082[33082] - Add an option to disable event normalization when creating a `beat.Client`. {pull}33657[33657] +- Add the file path of the instance lock on the error when it's is already locked {pull}33788[33788] ==== Deprecated diff --git a/libbeat/cmd/instance/locks/lock.go b/libbeat/cmd/instance/locks/lock.go index 0da72726182b..5d7fc8d2e35d 100644 --- a/libbeat/cmd/instance/locks/lock.go +++ b/libbeat/cmd/instance/locks/lock.go @@ -50,7 +50,7 @@ var ( // ErrAlreadyLocked is returned when a lock on the data path is attempted but // unsuccessful because another Beat instance already has the lock on the same // data path. - ErrAlreadyLocked = fmt.Errorf("data path already locked by another beat. Please make sure that multiple beats are not sharing the same data path (path.data).") + ErrAlreadyLocked = fmt.Errorf("data path already locked by another beat. Please make sure that multiple beats are not sharing the same data path (path.data)") // ErrLockfileEmpty is returned by readExistingPidfile() when an existing pidfile is found, but the file is empty. ErrLockfileEmpty = fmt.Errorf("lockfile is empty") @@ -112,7 +112,7 @@ func (lock *Locker) Lock() error { // case: lock could not be obtained. if !isLocked { // if we're here, things are probably unrecoverable, as we've previously checked for a lockfile. Exit. - return ErrAlreadyLocked + return fmt.Errorf("%s: %w", lock.filePath, ErrAlreadyLocked) } return nil