mirror of
https://github.com/siderolabs/talos.git
synced 2025-10-25 22:41:10 +02:00
fix: use a fresh context for etcd unlock
By the time unlock is called, context might be already canceled. Signed-off-by: Andrey Smirnov <andrey.smirnov@siderolabs.com>
This commit is contained in:
parent
84cd7dbec4
commit
07f78182c6
@ -7,6 +7,7 @@ package etcd
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
"go.etcd.io/etcd/client/v3/concurrency"
|
||||
"go.uber.org/zap"
|
||||
@ -38,7 +39,16 @@ func WithLock(ctx context.Context, key string, logger *zap.Logger, f func() erro
|
||||
|
||||
logger.Debug("mutex acquired", zap.String("key", key))
|
||||
|
||||
defer mutex.Unlock(ctx) //nolint:errcheck
|
||||
defer func() {
|
||||
logger.Debug("releasing mutex", zap.String("key", key))
|
||||
|
||||
unlockCtx, unlockCancel := context.WithTimeout(context.Background(), 30*time.Second)
|
||||
defer unlockCancel()
|
||||
|
||||
if err = mutex.Unlock(unlockCtx); err != nil {
|
||||
logger.Error("error releasing mutex", zap.String("key", key), zap.Error(err))
|
||||
}
|
||||
}()
|
||||
|
||||
return f()
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user