]> Cypherpunks repositories - goredo.git/commitdiff
Randomise sleep time while waiting for the lock
authorSergey Matveev <stargrave@stargrave.org>
Tue, 7 Jan 2025 10:59:37 +0000 (13:59 +0300)
committerSergey Matveev <stargrave@stargrave.org>
Tue, 7 Jan 2025 11:04:22 +0000 (14:04 +0300)
run.go

diff --git a/run.go b/run.go
index 5423b49bb335fdd89594604428ba21171d238f52..1b00bf005f411dc6c6a9bcc8a2d5b36a5e4a15bb 100644 (file)
--- a/run.go
+++ b/run.go
@@ -27,6 +27,7 @@ import (
        "io"
        "io/fs"
        "log"
+       mrand "math/rand"
        "os"
        "os/exec"
        "path"
@@ -228,7 +229,7 @@ func runScript(tgt *Tgt, errs chan error, forced, traced bool) error {
                LockAgain:
                        if err = unix.FcntlFlock(fdLock.Fd(), unix.F_SETLKW, &flock); err != nil {
                                if errors.Is(err, unix.EDEADLK) || errors.Is(err, unix.EINTR) {
-                                       time.Sleep(10 * time.Millisecond)
+                                       time.Sleep(time.Duration(1+mrand.Intn(20)) * time.Millisecond)
                                        goto LockAgain
                                }
                                log.Fatalln(err, fdLock.Name())