Skip to content

Commit 93640c5

Browse files
authored
Handle phantom public-config change (#2359)
Sometimes nodes reboot randomly because they receive phantom public-config changes. This was a code bug because we didn't handle ctx cancelation which caused the channel to receive a "zero" event which containes no data which causes the node to remove it's public config and then reboot this happens only with nodes that have pulic config
1 parent 160dfc6 commit 93640c5

File tree

3 files changed

+5
-5
lines changed

3 files changed

+5
-5
lines changed

cmds/modules/noded/main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,7 @@ func action(cli *cli.Context) error {
235235

236236
go func() {
237237
for {
238-
if err := public(ctx, node, env, redis, consumer); err != nil {
238+
if err := public(ctx, node, redis, consumer); err != nil {
239239
log.Error().Err(err).Msg("setting public config failed")
240240
<-time.After(10 * time.Second)
241241
}

cmds/modules/noded/public.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import (
99
substrate "github.com/threefoldtech/tfchain/clients/tfchain-client-go"
1010
"github.com/threefoldtech/zbus"
1111
"github.com/threefoldtech/zos/pkg"
12-
"github.com/threefoldtech/zos/pkg/environment"
1312
"github.com/threefoldtech/zos/pkg/events"
1413
"github.com/threefoldtech/zos/pkg/stubs"
1514
)
@@ -31,7 +30,7 @@ func setPublicConfig(ctx context.Context, cl zbus.Client, cfg *substrate.PublicC
3130
}
3231

3332
// public sets and watches changes to public config on chain and tries to apply the provided setup
34-
func public(ctx context.Context, nodeID uint32, env environment.Environment, cl zbus.Client, events *events.RedisConsumer) error {
33+
func public(ctx context.Context, nodeID uint32, cl zbus.Client, events *events.RedisConsumer) error {
3534
ch, err := events.PublicConfig(ctx)
3635
if err != nil {
3736
return errors.Wrap(err, "failed to subscribe to node events")
@@ -57,8 +56,9 @@ reapply:
5756

5857
for {
5958
select {
59+
case <-ctx.Done():
60+
return nil
6061
case event := <-ch:
61-
6262
log.Info().Msgf("got a public config update: %+v", event.PublicConfig)
6363
var cfg *substrate.PublicConfig
6464
if event.PublicConfig.HasValue {

pkg/events/redis.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -265,7 +265,7 @@ func (r *RedisConsumer) consumer(ctx context.Context, stream string, ch reflect.
265265
if chosen == 0 {
266266
return
267267
}
268-
} else if err != nil {
268+
} else {
269269
logger.Error().Err(err).Str("id", message.ID).Msg("failed to handle message")
270270
}
271271

0 commit comments

Comments
 (0)