Skip to content

Commit a3d6edc

Browse files
author
Kazuyoshi Kato
committed
content: return the error with its timestamp
The current timestamp is probably included in production logs, but won't be in testing environments such as GitHub Actions. Signed-off-by: Kazuyoshi Kato <[email protected]>
1 parent 218db0f commit a3d6edc

2 files changed

Lines changed: 8 additions & 2 deletions

File tree

content/local/locks.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,13 @@ func tryLock(ref string) error {
4141
defer locksMu.Unlock()
4242

4343
if v, ok := locks[ref]; ok {
44-
return errors.Wrapf(errdefs.ErrUnavailable, "ref %s locked since %s", ref, v.since)
44+
// Returning the duration may help developers distinguish dead locks (long duration) from
45+
// lock contentions (short duration).
46+
now := time.Now()
47+
return errors.Wrapf(
48+
errdefs.ErrUnavailable,
49+
"ref %s locked for %s (since %s)", ref, now.Sub(v.since), v.since,
50+
)
4551
}
4652

4753
locks[ref] = &lock{time.Now()}

content/local/locks_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,5 +28,5 @@ func TestTryLock(t *testing.T) {
2828
defer unlock("testref")
2929

3030
err = tryLock("testref")
31-
assert.ErrorContains(t, err, "ref testref locked since ")
31+
assert.ErrorContains(t, err, "ref testref locked for ")
3232
}

0 commit comments

Comments
 (0)