Skip to content

Commit e0bb1dc

Browse files
committed
fix: graceful shutdown on signing policy error
1 parent f4ffa5d commit e0bb1dc

3 files changed

Lines changed: 11 additions & 3 deletions

File tree

client/manager/manager.go

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ func New(configs *config.UserRaw, attestationTypeConfig config.AttestationTypes,
5151
}
5252

5353
// Run starts processing data received through the manager's channels.
54-
func (m *Manager) Run(ctx context.Context) {
54+
func (m *Manager) Run(ctx context.Context, cancel context.CancelFunc) {
5555
// Get signing policy first as we cannot process any other message types
5656
// without a signing policy.
5757
var signingPolicies []shared.VotersData
@@ -82,6 +82,14 @@ func (m *Manager) Run(ctx context.Context) {
8282
err := m.OnSigningPolicy(signingPolicies[i])
8383
if err != nil {
8484
logger.Error("signing policy error:", err)
85+
shutdownTime := time.Unix(int64(timing.RoundStartTS(signingPolicies[i].Policy.StartVotingRoundId+1)), 0)
86+
logger.Infof("scheduling shutdown at %v", shutdownTime)
87+
logger.Infof("shutdown after reward epoch %d after the end of voting round %d", signingPolicies[i].Policy.RewardEpochId, signingPolicies[i].Policy.StartVotingRoundId-1)
88+
go func(cancel context.CancelFunc, deadline time.Time) {
89+
time.Sleep(time.Until(deadline))
90+
logger.Errorf("shutting down due to an error in signing policy")
91+
cancel()
92+
}(cancel, shutdownTime)
8593
}
8694
}
8795
deleted := m.signingPolicyStorage.RemoveBefore(m.lastRoundCreated) // delete all signing policies that have already ended

client/manager/manager_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ func TestManager(t *testing.T) {
161161

162162
// run manager
163163
ctx, cancel := context.WithCancel(context.Background())
164-
go mngr.Run(ctx)
164+
go mngr.Run(ctx, cancel)
165165

166166
time.Sleep(1 * time.Second)
167167

main/main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ func main() {
5858
if err != nil {
5959
logger.Panicf("failed to create the manager: %s", err)
6060
}
61-
go mngr.Run(ctx)
61+
go mngr.Run(ctx, cancel)
6262

6363
// Run attestation client server
6464
srv := server.New(&sharedDataPipes.Rounds, userConfigRaw.ProtocolID, userConfigRaw.RestServer)

0 commit comments

Comments
 (0)