Skip to content

Commit c24617c

Browse files
Add release timeout
1 parent cfa5982 commit c24617c

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

pkg/store/leaderelection/leaderelection.go

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,8 @@ import (
6565
)
6666

6767
const (
68-
JitterFactor = 1.2
68+
JitterFactor = 1.2
69+
releaseTimeout = 15 * time.Second
6970
)
7071

7172
// NewLeaderElector creates a LeaderElector from a LeaderElectionConfig
@@ -267,7 +268,12 @@ func (le *LeaderElector) renew(ctx context.Context) {
267268
if le.config.ReleaseOnCancel {
268269
// Use the background context, not the one that was passed in originally. If
269270
// the latter was cancelled, then we can't actually do the release.
270-
le.release(context.Background())
271+
releaseCtx, releaseCancel := context.WithTimeout(
272+
context.Background(),
273+
releaseTimeout,
274+
)
275+
defer releaseCancel()
276+
le.release(releaseCtx)
271277
}
272278
}
273279

0 commit comments

Comments
 (0)