-
Notifications
You must be signed in to change notification settings - Fork 3.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
refactor: cleanup server logic #15041
Conversation
go func(enableUnsafeCORS bool) { | ||
s.logger.Info("starting API server...", "address", cfg.API.Address) | ||
|
||
return tmrpcserver.Serve(s.listener, s.Router, s.logger, cmtCfg) | ||
if enableUnsafeCORS { | ||
allowAllCORS := handlers.CORS(handlers.AllowedHeaders([]string{"Content-Type"})) | ||
errCh <- tmrpcserver.Serve(s.listener, allowAllCORS(s.Router), s.logger, cmtCfg) | ||
} else { | ||
errCh <- tmrpcserver.Serve(s.listener, s.Router, s.logger, cmtCfg) | ||
} | ||
}(cfg.API.EnableUnsafeCORS) |
Check notice
Code scanning / CodeQL
Spawning a Go routine
} | ||
}) | ||
|
||
return g.Wait() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This code is unreachable, and the loop above is unnecessary.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How is it un-reachable? I've tested it and it indeed gets gracefully exits.
server/start.go
Outdated
g.Go(func() error { | ||
return servergrpc.StartGRPCServer(ctx, svrCtx.Logger.With("module", "grpc-server"), config.GRPC, grpcSrv) | ||
}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So starting a server requires 2 routines long-running routines? One inside the call and the one for the caller. This can be greatly simplified
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not quite sure I follow?
There is the main parent process, server.go
, i.e. the application process. Then there are 2 explicitly spawned goroutines, one for the API server (if enabled) and one for the gRPC server (if enabled). Both of these servers are blocking processes. Starting them in a goroutine is pretty idiomatic IMO.
What is wrong with starting the gRPC and API servers in separate goroutines? What do you see that can be cleaned up?
Is there any logic that handles the errors coming from |
(cherry picked from commit 7f99ad5) # Conflicts: # CHANGELOG.md # go.mod # go.sum # server/api/server.go # server/start.go # server/types/app.go # server/util.go # simapp/go.sum # tests/go.sum # testutil/network/network.go # testutil/network/util.go # tools/confix/go.mod # tools/confix/go.sum # x/evidence/go.mod # x/evidence/go.sum # x/feegrant/go.mod # x/feegrant/go.sum # x/nft/go.mod # x/nft/go.sum # x/upgrade/go.mod # x/upgrade/go.sum
@Mergifyio backport release/v0.47.x |
✅ Backports have been created
|
cleanup for easier review
…e configurable, and add support for domain sockets for gRPC server and gRPC web server. ctx.Done() support and was added in 0.50 with cosmos#15041 server start up time was removed in 0.50 with cosmos#15041
…e configurable, and add support for domain sockets for gRPC server and gRPC web server. ctx.Done() support and was added in 0.50 with cosmos#15041 server start up time was removed in 0.50 with cosmos#15041
ctx.Done() support was added in 0.50 with cosmos#15041 server start up time was removed in 0.50 with cosmos#15041
ctx.Done() support was added in 0.50 with cosmos#15041 server start up time was removed in 0.50 with cosmos#15041
ctx.Done() support was added in 0.50 with cosmos#15041 server start up time was removed in 0.50 with cosmos#15041
ctx.Done() support was added in 0.50 with cosmos#15041 server start up time was removed in 0.50 with cosmos#15041
ctx.Done() support was added in 0.50 with cosmos#15041 server start up time was removed in 0.50 with cosmos#15041
ctx.Done() support was added in 0.50 with cosmos#15041 server start up time was removed in 0.50 with cosmos#15041
Description
Closes: #14429
This PR addresses the duct tape that was used during in-process application start. Specifically, we refactor the in-process logic to correctly start the gRPC and API servers, with correct graceful shutdown and signal handling. No more random clunky sleeps.
I took the approach here from the approach I've used for both Umee and Numia, i.e. use
Context
andErrGroup
as communication mechanisms for blocking processes, effectively forcing the caller to ensure graceful shutdown and starting via theContext
.Changelog
Context
that will gracefully indicate shutdownif
statements made no sense)Tested
Author Checklist
All items are required. Please add a note to the item if the item is not applicable and
please add links to any relevant follow up issues.
I have...
!
to the type prefix if API or client breaking changeCHANGELOG.md
Reviewers Checklist
All items are required. Please add a note if the item is not applicable and please add
your handle next to the items reviewed if you only reviewed selected items.
I have...
!
in the type prefix if API or client breaking change