Skip to content

Commit 0c4e028

Browse files
committed
fix: shutdown snpjrpc server on context done
1 parent bd34e21 commit 0c4e028

File tree

2 files changed

+6
-3
lines changed

2 files changed

+6
-3
lines changed

rolling-shutter/snapshot/snapshot.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,8 +91,6 @@ func (snp *Snapshot) Start(ctx context.Context, runner service.Runner) error {
9191
hub := hubapi.New(snp.Config.SnapshotHubURL)
9292
snp.hubapi = hub
9393

94-
runner.Defer(snp.jrpc.Shutdown)
95-
9694
snp.setupP2PHandler()
9795
return runner.StartService(snp.getServices()...)
9896
}

rolling-shutter/snapshot/snpjrpc/server.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ func New(
145145
return &jrpc
146146
}
147147

148-
func (snpjrpc *SnpJRPC) Start(_ context.Context, group service.Runner) error {
148+
func (snpjrpc *SnpJRPC) Start(ctx context.Context, group service.Runner) error { //nolint:unparam
149149
group.Go(func() error {
150150
httpServer := snpjrpc.Server.Prepare()
151151
log.Info().Str("address", snpjrpc.Server.Host).Msg("Running JSON-RPC server at")
@@ -154,6 +154,11 @@ func (snpjrpc *SnpJRPC) Start(_ context.Context, group service.Runner) error {
154154
}
155155
return nil
156156
})
157+
group.Go(func() error {
158+
<-ctx.Done()
159+
snpjrpc.Shutdown()
160+
return ctx.Err()
161+
})
157162
return nil
158163
}
159164

0 commit comments

Comments
 (0)