mirror of https://github.com/docker/docs.git
Fix race on shutting down
Docker-DCO-1.1-Signed-off-by: Alexandr Morozov <lk4d4math@gmail.com> (github: LK4D4)
This commit is contained in:
parent
c4990ab999
commit
ce9e9ff4a1
|
@ -39,6 +39,7 @@ import (
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
"sync"
|
"sync"
|
||||||
|
"sync/atomic"
|
||||||
"syscall"
|
"syscall"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
@ -87,17 +88,17 @@ func InitServer(job *engine.Job) engine.Status {
|
||||||
c := make(chan os.Signal, 1)
|
c := make(chan os.Signal, 1)
|
||||||
gosignal.Notify(c, os.Interrupt, syscall.SIGTERM, syscall.SIGQUIT)
|
gosignal.Notify(c, os.Interrupt, syscall.SIGTERM, syscall.SIGQUIT)
|
||||||
go func() {
|
go func() {
|
||||||
interruptCount := 0
|
interruptCount := uint32(0)
|
||||||
for sig := range c {
|
for sig := range c {
|
||||||
go func() {
|
go func(sig os.Signal) {
|
||||||
log.Printf("Received signal '%v', starting shutdown of docker...\n", sig)
|
log.Printf("Received signal '%v', starting shutdown of docker...\n", sig)
|
||||||
switch sig {
|
switch sig {
|
||||||
case os.Interrupt, syscall.SIGTERM:
|
case os.Interrupt, syscall.SIGTERM:
|
||||||
// If the user really wants to interrupt, let him do so.
|
// If the user really wants to interrupt, let him do so.
|
||||||
if interruptCount < 3 {
|
if atomic.LoadUint32(&interruptCount) < 3 {
|
||||||
interruptCount++
|
atomic.AddUint32(&interruptCount, 1)
|
||||||
// Initiate the cleanup only once
|
// Initiate the cleanup only once
|
||||||
if interruptCount == 1 {
|
if atomic.LoadUint32(&interruptCount) == 1 {
|
||||||
utils.RemovePidFile(srv.daemon.Config().Pidfile)
|
utils.RemovePidFile(srv.daemon.Config().Pidfile)
|
||||||
srv.Close()
|
srv.Close()
|
||||||
} else {
|
} else {
|
||||||
|
@ -109,7 +110,7 @@ func InitServer(job *engine.Job) engine.Status {
|
||||||
case syscall.SIGQUIT:
|
case syscall.SIGQUIT:
|
||||||
}
|
}
|
||||||
os.Exit(128 + int(sig.(syscall.Signal)))
|
os.Exit(128 + int(sig.(syscall.Signal)))
|
||||||
}()
|
}(sig)
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
job.Eng.Hack_SetGlobalVar("httpapi.server", srv)
|
job.Eng.Hack_SetGlobalVar("httpapi.server", srv)
|
||||||
|
|
Loading…
Reference in New Issue