Skip to content

Return original error when WaitLock times out #47

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

Merged
merged 2 commits into from
May 6, 2025
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
3 changes: 2 additions & 1 deletion fslock.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,8 @@ retry:
}
select {
case <-ctx.Done():
return nil, ctx.Err()
log.Warnf("did not acquire lock: %s", ctx.Err())
return nil, err
case <-ticker.C:
goto retry
}
Expand Down
10 changes: 7 additions & 3 deletions fslock_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package fslock_test
import (
"bufio"
"context"
"errors"
"os"
"os/exec"
"path/filepath"
Expand Down Expand Up @@ -158,6 +157,7 @@ func TestWaitLock(t *testing.T) {
someFile = "somefile"
permErr = "permission denied"
heldErr = "lock is already held by us"
wantErr = "someone else has the lock"
)

confdir := t.TempDir()
Expand Down Expand Up @@ -259,7 +259,11 @@ func TestWaitLock(t *testing.T) {
if err == nil {
t.Fatalf("parent successfully acquired the lock")
}
if !errors.Is(err, context.DeadlineExceeded) {
t.Fatalf("did not get expected error: %s", context.DeadlineExceeded)
pe, ok = err.(*os.PathError)
if !ok {
t.Fatalf("wrong error type %T", err)
}
if got := pe.Error(); !strings.Contains(got, wantErr) {
t.Fatalf("error %q does not contain %q", got, wantErr)
}
}