fix(webserver): always panic in case of an issue in webserver
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
@ -3,7 +3,6 @@ package webserver
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"log"
|
||||
"net/http"
|
||||
"os"
|
||||
@ -25,10 +24,11 @@ type ExecuteServerParams struct {
|
||||
|
||||
// ExecuteServer will launche a http.Server and handle the "exit" signals and gracefully stop the server
|
||||
// and call the cleanup function.
|
||||
func ExecuteServer(ctx context.Context, srv *http.Server, params *ExecuteServerParams) error {
|
||||
func ExecuteServer(ctx context.Context, srv *http.Server, params *ExecuteServerParams) {
|
||||
|
||||
if srv == nil {
|
||||
return fmt.Errorf("missing http.server params")
|
||||
log.Panicf("missing http.server params")
|
||||
return
|
||||
}
|
||||
|
||||
if srv.ReadTimeout == 0 {
|
||||
@ -44,6 +44,7 @@ func ExecuteServer(ctx context.Context, srv *http.Server, params *ExecuteServerP
|
||||
go func() {
|
||||
if err := srv.ListenAndServe(); !errors.Is(err, http.ErrServerClosed) {
|
||||
log.Panicf("HTTP server error: %v", err)
|
||||
return
|
||||
}
|
||||
log.Printf("Stopped serving new connections.")
|
||||
}()
|
||||
@ -57,16 +58,15 @@ func ExecuteServer(ctx context.Context, srv *http.Server, params *ExecuteServerP
|
||||
|
||||
if err := srv.Shutdown(shutdownCtx); err != nil {
|
||||
log.Panicf("HTTP shutdown error: %v", err)
|
||||
return
|
||||
}
|
||||
|
||||
if params != nil && params.Cleanup != nil {
|
||||
if err := params.Cleanup(); err != nil {
|
||||
log.Printf("Impossible to cleanup correctly after shutdown. error : %v", err)
|
||||
return nil
|
||||
log.Panicf("Impossible to cleanup correctly after shutdown. error : %v", err)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
log.Print("Graceful shutdown complete.")
|
||||
|
||||
return nil
|
||||
}
|
||||
|
Reference in New Issue
Block a user