Merge pull request #3661 from alexey-savchuk/fix-panic-on-sighup

services/rpcsrv: Return a new server by pointer
This commit is contained in:
Anna Shaleva 2024-11-06 11:04:44 +03:00 committed by GitHub
commit b6516586d5
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 7 additions and 7 deletions

View file

@ -505,7 +505,7 @@ func startServer(ctx *cli.Context) error {
} }
errChan := make(chan error) errChan := make(chan error)
rpcServer := rpcsrv.New(chain, cfg.ApplicationConfiguration.RPC, serv, oracleSrv, log, errChan) rpcServer := rpcsrv.New(chain, cfg.ApplicationConfiguration.RPC, serv, oracleSrv, log, errChan)
serv.AddService(&rpcServer) serv.AddService(rpcServer)
serv.Start() serv.Start()
if !cfg.ApplicationConfiguration.RPC.StartWhenSynchronized { if !cfg.ApplicationConfiguration.RPC.StartWhenSynchronized {
@ -561,10 +561,10 @@ Main:
logLevel.SetLevel(newLogLevel) logLevel.SetLevel(newLogLevel)
log.Warn("using new logging level", zap.Stringer("level", newLogLevel)) log.Warn("using new logging level", zap.Stringer("level", newLogLevel))
} }
serv.DelService(&rpcServer) serv.DelService(rpcServer)
rpcServer.Shutdown() rpcServer.Shutdown()
rpcServer = rpcsrv.New(chain, cfgnew.ApplicationConfiguration.RPC, serv, oracleSrv, log, errChan) rpcServer = rpcsrv.New(chain, cfgnew.ApplicationConfiguration.RPC, serv, oracleSrv, log, errChan)
serv.AddService(&rpcServer) serv.AddService(rpcServer)
if !cfgnew.ApplicationConfiguration.RPC.StartWhenSynchronized || serv.IsInSync() { if !cfgnew.ApplicationConfiguration.RPC.StartWhenSynchronized || serv.IsInSync() {
// Here similar to the initial run (see above for-loop), so async. // Here similar to the initial run (see above for-loop), so async.
go rpcServer.Start() go rpcServer.Start()

View file

@ -178,7 +178,7 @@ func NewTestChain(t *testing.T, f func(*config.Config), run bool) (*core.Blockch
rpcServer := rpcsrv.New(chain, cfg.ApplicationConfiguration.RPC, netSrv, nil, logger, errCh) rpcServer := rpcsrv.New(chain, cfg.ApplicationConfiguration.RPC, netSrv, nil, logger, errCh)
rpcServer.Start() rpcServer.Start()
return chain, &rpcServer, netSrv return chain, rpcServer, netSrv
} }
func NewExecutor(t *testing.T, needChain bool) *Executor { func NewExecutor(t *testing.T, needChain bool) *Executor {

View file

@ -269,7 +269,7 @@ var rpcWsHandlers = map[string]func(*Server, params.Params, *subscriber) (any, *
// New creates a new Server struct. Pay attention that orc is expected to be either // New creates a new Server struct. Pay attention that orc is expected to be either
// untyped nil or non-nil structure implementing OracleHandler interface. // untyped nil or non-nil structure implementing OracleHandler interface.
func New(chain Ledger, conf config.RPC, coreServer *network.Server, func New(chain Ledger, conf config.RPC, coreServer *network.Server,
orc OracleHandler, log *zap.Logger, errChan chan<- error) Server { orc OracleHandler, log *zap.Logger, errChan chan<- error) *Server {
protoCfg := chain.GetConfig().ProtocolConfiguration protoCfg := chain.GetConfig().ProtocolConfiguration
if conf.SessionEnabled { if conf.SessionEnabled {
if conf.SessionExpirationTime <= 0 { if conf.SessionExpirationTime <= 0 {
@ -339,7 +339,7 @@ func New(chain Ledger, conf config.RPC, coreServer *network.Server,
} }
} }
return Server{ return &Server{
http: httpServers, http: httpServers,
https: tlsServers, https: tlsServers,

View file

@ -131,7 +131,7 @@ func wrapUnitTestChain(t testing.TB, chain *core.Blockchain, orc OracleHandler,
handler := http.HandlerFunc(rpcServer.handleHTTPRequest) handler := http.HandlerFunc(rpcServer.handleHTTPRequest)
srv := httptest.NewServer(handler) srv := httptest.NewServer(handler)
t.Cleanup(srv.Close) t.Cleanup(srv.Close)
return chain, &rpcServer, srv return chain, rpcServer, srv
} }
func initClearServerWithCustomConfig(t testing.TB, ccfg func(configuration *config.Config)) (*core.Blockchain, *Server, *httptest.Server) { func initClearServerWithCustomConfig(t testing.TB, ccfg func(configuration *config.Config)) (*core.Blockchain, *Server, *httptest.Server) {