Skip to content

Commit

Permalink
stop RPC servers in shutdown (#1361)
Browse files Browse the repository at this point in the history
  • Loading branch information
darioush authored Oct 16, 2024
1 parent e93eb1e commit 273d3d8
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions plugin/evm/vm.go
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,9 @@ type VM struct {
ethTxGossipHandler p2p.Handler
ethTxPushGossiper avalancheUtils.Atomic[*gossip.PushGossiper[*GossipEthTx]]
ethTxPullGossiper gossip.Gossiper

// RPC handlers (should be stopped before closing chaindb)
rpcHandlers []interface{ Stop() }
}

// Initialize implements the snowman.ChainVM interface
Expand Down Expand Up @@ -826,6 +829,10 @@ func (vm *VM) Shutdown(context.Context) error {
log.Error("error stopping state syncer", "err", err)
}
close(vm.shutdownChan)
// Stop RPC handlers before eth.Stop which will close the database
for _, handler := range vm.rpcHandlers {
handler.Stop()
}
vm.eth.Stop()
log.Info("Ethereum backend stop completed")
vm.shutdownWg.Wait()
Expand Down Expand Up @@ -1040,6 +1047,7 @@ func (vm *VM) CreateHandlers(context.Context) (map[string]http.Handler, error) {
vm.config.WSCPUMaxStored.Duration,
)

vm.rpcHandlers = append(vm.rpcHandlers, handler)
return apis, nil
}

Expand All @@ -1053,6 +1061,7 @@ func (vm *VM) CreateStaticHandlers(context.Context) (map[string]http.Handler, er
return nil, err
}

vm.rpcHandlers = append(vm.rpcHandlers, handler)
return map[string]http.Handler{
"/rpc": handler,
}, nil
Expand Down

0 comments on commit 273d3d8

Please sign in to comment.