-
Notifications
You must be signed in to change notification settings - Fork 4k
Open
Description
Locations
Description
The Start
function in the Server
struct initiates a goroutine that sends errors to an unbuffered channel errCh
. If the ctx.Done()
branch wins the race condition, the goroutine will block indefinitely, leading to a resource leak. Below is the relevant code snippet:
errCh := make(chan error)
go func(enableUnsafeCORS bool) {
s.logger.Info("starting API server...", "address", cfg.API.Address)
if enableUnsafeCORS {
allowAllCORS := handlers.CORS(handlers.AllowedHeaders([]string{"Content-Type"}))
errCh <- cmtrpcserver.Serve(s.listener, allowAllCORS(s.Router), cmtlogwrapper.CometLoggerWrapper{Logger: s.logger}, cmtCfg)
} else {
errCh <- cmtrpcserver.Serve(s.listener, s.Router, cmtlogwrapper.CometLoggerWrapper{Logger: s.logger}, cmtCfg)
}
}(cfg.API.EnableUnsafeCORS)
// Start a blocking select to wait for an indication to stop the server or that
// the server failed to start properly.
select {
case <-ctx.Done():
// The calling process canceled or closed the provided context, so we must
// gracefully stop the API server.
s.logger.Info("stopping API server...", "address", cfg.API.Address)
return s.Close()
case err := <-errCh:
s.logger.Error("failed to start API server", "err", err)
return err
}
The same issue exists in the function StartGRPCServer
.
Metadata
Metadata
Assignees
Labels
No labels