m/n/c/curator: handle election observation failure
Failure of the observation is signalled by closing the channel. Before
this fix, this caused a panic at the o.Kvs[0] indexing operation.
This bug was found after enabling WithPropagatePanic in the supervisor
TestHarness.
Change-Id: I94487720a106d752612153d23c83b4d9bff598f4
Reviewed-on: https://review.monogon.dev/c/monogon/+/2945
Reviewed-by: Serge Bazanski <serge@monogon.tech>
Vouch-Run-CI: Serge Bazanski <serge@monogon.tech>
Tested-by: Jenkins CI
diff --git a/metropolis/node/core/curator/curator.go b/metropolis/node/core/curator/curator.go
index 0026d28..5892090 100644
--- a/metropolis/node/core/curator/curator.go
+++ b/metropolis/node/core/curator/curator.go
@@ -204,7 +204,10 @@
// current leader.
for {
select {
- case o := <-observerC:
+ case o, ok := <-observerC:
+ if !ok {
+ return errors.New("election observation failed")
+ }
var lock ppb.LeaderElectionValue
if err := proto.Unmarshal(o.Kvs[0].Value, &lock); err != nil {
return fmt.Errorf("parsing existing lock value failed: %w", err)