Skip to content

Commit 26a2457

Browse files
authored
Ensure leader resignation on shutdown (#3790)
To ensure proper leadership resignation during shutdown, an independent context is created for election.Close, preventing failure due to the canceled parent context. Signed-off-by: Tomas Turek <tturek@redhat.com>
1 parent 57800f3 commit 26a2457

File tree

2 files changed

+4
-1
lines changed

2 files changed

+4
-1
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
## HEAD
44

55
* Bump golangci-lint to v2.1.6
6+
* Fix leader resignation during a graceful shutdown by @osmman in https://github.com/google/trillian/pull/3790
67

78
## v1.7.2
89

util/election/runner.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,8 +108,10 @@ func (er *Runner) Run(ctx context.Context, pending chan<- Resignation) {
108108

109109
klog.V(1).Infof("%s: start election-monitoring loop ", er.id)
110110
defer func() {
111+
closeCtx, closeCancel := context.WithTimeout(context.Background(), time.Second)
112+
defer closeCancel()
111113
klog.Infof("%s: shutdown election-monitoring loop", er.id)
112-
if err := er.election.Close(ctx); err != nil {
114+
if err := er.election.Close(closeCtx); err != nil {
113115
klog.Warningf("%s: election.Close: %v", er.id, err)
114116
}
115117
}()

0 commit comments

Comments
 (0)