fix(main.go): avoid closing the query engine until it is guaranteed to no longer be in use.

partially reverts https://github.com/prometheus/prometheus/pull/14064

fixes https://github.com/prometheus/prometheus/issues/15232

supersedes https://github.com/prometheus/prometheus/pull/15533

reusing Engine.Close() outside of tests will require more consideration.

Signed-off-by: machine424 <ayoubmrini424@gmail.com>
This commit is contained in:
machine424 2024-12-30 05:14:44 +01:00
parent 08c81b721a
commit 9823a93c42
No known key found for this signature in database
GPG key ID: A4B001A4FDEE017D
2 changed files with 2 additions and 9 deletions

View file

@ -989,18 +989,12 @@ func main() {
listeners, err := webHandler.Listeners()
if err != nil {
logger.Error("Unable to start web listener", "err", err)
if err := queryEngine.Close(); err != nil {
logger.Warn("Closing query engine failed", "err", err)
}
os.Exit(1)
}
err = toolkit_web.Validate(*webConfig)
if err != nil {
logger.Error("Unable to validate web configuration file", "err", err)
if err := queryEngine.Close(); err != nil {
logger.Warn("Closing query engine failed", "err", err)
}
os.Exit(1)
}
@ -1022,9 +1016,6 @@ func main() {
case <-cancel:
reloadReady.Close()
}
if err := queryEngine.Close(); err != nil {
logger.Warn("Closing query engine failed", "err", err)
}
return nil
},
func(err error) {

View file

@ -436,6 +436,8 @@ func NewEngine(opts EngineOpts) *Engine {
}
// Close closes ng.
// Callers must ensure the engine is really no longer in use before calling this to avoid
// issues failures like in https://github.com/prometheus/prometheus/issues/15232
func (ng *Engine) Close() error {
if ng == nil {
return nil