go: die even more reliably on error
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:
parent
1359750c97
commit
672132a109
45
run.go
45
run.go
@ -139,42 +139,31 @@ func run() error {
|
|||||||
// channel used to check whether the app had troubles starting up.
|
// channel used to check whether the app had troubles starting up.
|
||||||
started := make(chan error, 1)
|
started := make(chan error, 1)
|
||||||
|
|
||||||
|
defer close(started)
|
||||||
|
|
||||||
go func(ok chan error) {
|
go func(ok chan error) {
|
||||||
p := setting.Port()
|
p := setting.Port()
|
||||||
h := setting.Host()
|
h := setting.Host()
|
||||||
|
|
||||||
address := h + ":" + strconv.Itoa(p)
|
address := h + ":" + strconv.Itoa(p)
|
||||||
|
|
||||||
if err = e.Start(address); err != nil && err != http.ErrServerClosed {
|
if err := e.Start(address); err != nil && err != http.ErrServerClosed {
|
||||||
log.Error("troubles running the server, bailing", "error", err.Error())
|
log.Error("troubles running the server, bailing...", "error", err)
|
||||||
|
|
||||||
shutdownTimeout := 3 * time.Second
|
|
||||||
ctx, cancel := context.WithTimeout(
|
|
||||||
context.Background(), shutdownTimeout,
|
|
||||||
)
|
|
||||||
|
|
||||||
defer func() {
|
|
||||||
cancel()
|
|
||||||
started <- err
|
started <- err
|
||||||
close(started)
|
|
||||||
}()
|
|
||||||
|
|
||||||
log.Info("shutting down the server")
|
|
||||||
|
|
||||||
err = e.Shutdown(ctx)
|
|
||||||
if err == ctx.Err() && err != nil {
|
|
||||||
log.Info("RIP this is taking too long")
|
|
||||||
started <- err
|
|
||||||
|
|
||||||
e.Server.Close()
|
|
||||||
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
started <- err
|
started <- nil
|
||||||
}(started)
|
}(started)
|
||||||
|
|
||||||
|
quit := make(chan os.Signal, 1)
|
||||||
|
|
||||||
|
signal.Notify(quit, os.Interrupt)
|
||||||
|
signal.Notify(quit, syscall.SIGTERM)
|
||||||
|
signal.Notify(quit, syscall.SIGHUP)
|
||||||
|
|
||||||
// non-blocking channel receive.
|
// non-blocking channel receive.
|
||||||
select {
|
select {
|
||||||
case err := <-started:
|
case err := <-started:
|
||||||
@ -182,16 +171,7 @@ func run() error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
default:
|
case <-quit:
|
||||||
}
|
|
||||||
|
|
||||||
quit := make(chan os.Signal, 1)
|
|
||||||
|
|
||||||
signal.Notify(quit, os.Interrupt)
|
|
||||||
signal.Notify(quit, syscall.SIGTERM)
|
|
||||||
signal.Notify(quit, syscall.SIGHUP)
|
|
||||||
<-quit
|
|
||||||
|
|
||||||
shutdownTimeout := 10 * time.Second
|
shutdownTimeout := 10 * time.Second
|
||||||
|
|
||||||
ctx, cancel := context.WithTimeout(context.Background(), shutdownTimeout)
|
ctx, cancel := context.WithTimeout(context.Background(), shutdownTimeout)
|
||||||
@ -210,6 +190,7 @@ func run() error {
|
|||||||
log.Error("There was an error shutting the server down")
|
log.Error("There was an error shutting the server down")
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user