From a3d6edc0eddeb380dceed84884a78b5dc621023b Mon Sep 17 00:00:00 2001 From: Kazuyoshi Kato Date: Mon, 9 Aug 2021 16:37:07 -0700 Subject: [PATCH] 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 --- content/local/locks.go | 8 +++++++- content/local/locks_test.go | 2 +- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/content/local/locks.go b/content/local/locks.go index d1d2d564d..077b6241e 100644 --- a/content/local/locks.go +++ b/content/local/locks.go @@ -41,7 +41,13 @@ func tryLock(ref string) error { defer locksMu.Unlock() if v, ok := locks[ref]; ok { - return errors.Wrapf(errdefs.ErrUnavailable, "ref %s locked since %s", ref, v.since) + // Returning the duration may help developers distinguish dead locks (long duration) from + // lock contentions (short duration). + now := time.Now() + return errors.Wrapf( + errdefs.ErrUnavailable, + "ref %s locked for %s (since %s)", ref, now.Sub(v.since), v.since, + ) } locks[ref] = &lock{time.Now()} diff --git a/content/local/locks_test.go b/content/local/locks_test.go index c9d0034cc..3d1912dd5 100644 --- a/content/local/locks_test.go +++ b/content/local/locks_test.go @@ -28,5 +28,5 @@ func TestTryLock(t *testing.T) { defer unlock("testref") err = tryLock("testref") - assert.ErrorContains(t, err, "ref testref locked since ") + assert.ErrorContains(t, err, "ref testref locked for ") }