mirror of
https://github.com/caddyserver/caddy.git
synced 2025-01-28 04:45:56 +03:00
Clean up certmagic locks on signaled process exit
This should help prevent hanging in some cases when the process is restarted and tries to obtain or renew a certificate, for example, but the lock remains from the previous shutdown (which was during the same operation). Only works if the process is cleanly shut down with a signal it can capture.
This commit is contained in:
parent
0c626fbc2e
commit
6720bdfb55
4 changed files with 9 additions and 3 deletions
2
go.mod
2
go.mod
|
@ -14,7 +14,7 @@ require (
|
|||
github.com/klauspost/cpuid v1.2.0
|
||||
github.com/kylelemons/godebug v0.0.0-20170820004349-d65d576e9348 // indirect
|
||||
github.com/lucas-clemente/quic-go v0.10.2
|
||||
github.com/mholt/certmagic v0.5.0
|
||||
github.com/mholt/certmagic v0.6.1-0.20190619225040-c7a9fdb17816
|
||||
github.com/naoina/go-stringutil v0.1.0 // indirect
|
||||
github.com/naoina/toml v0.1.1
|
||||
github.com/russross/blackfriday v0.0.0-20170610170232-067529f716f4
|
||||
|
|
4
go.sum
4
go.sum
|
@ -44,8 +44,8 @@ github.com/lucas-clemente/quic-go v0.10.2/go.mod h1:hvaRS9IHjFLMq76puFJeWNfmn+H7
|
|||
github.com/lucas-clemente/quic-go-certificates v0.0.0-20160823095156-d2f86524cced h1:zqEC1GJZFbGZA0tRyNZqRjep92K5fujFtFsu5ZW7Aug=
|
||||
github.com/lucas-clemente/quic-go-certificates v0.0.0-20160823095156-d2f86524cced/go.mod h1:NCcRLrOTZbzhZvixZLlERbJtDtYsmMw8Jc4vS8Z0g58=
|
||||
github.com/marten-seemann/qtls v0.2.3/go.mod h1:xzjG7avBwGGbdZ8dTGxlBnLArsVKLvwmjgmPuiQEcYk=
|
||||
github.com/mholt/certmagic v0.5.0 h1:lYXxsLUFya/I3BgDCrfuwcMQOB+4auzI8CCzpK41tjc=
|
||||
github.com/mholt/certmagic v0.5.0/go.mod h1:g4cOPxcjV0oFq3qwpjSA30LReKD8AoIfwAY9VvG35NY=
|
||||
github.com/mholt/certmagic v0.6.1-0.20190619225040-c7a9fdb17816 h1:DEoTKH/n8k9JXYqM/A3AmW407Q5Rncrkuipqu0mztcg=
|
||||
github.com/mholt/certmagic v0.6.1-0.20190619225040-c7a9fdb17816/go.mod h1:g4cOPxcjV0oFq3qwpjSA30LReKD8AoIfwAY9VvG35NY=
|
||||
github.com/miekg/dns v1.1.3 h1:1g0r1IvskvgL8rR+AcHzUA+oFmGcQlaIm4IqakufeMM=
|
||||
github.com/miekg/dns v1.1.3/go.mod h1:W1PPwlIAgtquWBMBEV9nkV9Cazfe8ScdGz/Lj7v3Nrg=
|
||||
github.com/naoina/go-stringutil v0.1.0 h1:rCUeRUHjBjGTSHl0VC00jUPLz8/F9dDzYI70Hzifhks=
|
||||
|
|
|
@ -21,6 +21,7 @@ import (
|
|||
"sync"
|
||||
|
||||
"github.com/mholt/caddy/telemetry"
|
||||
"github.com/mholt/certmagic"
|
||||
)
|
||||
|
||||
// TrapSignals create signal handlers for all applicable signals for this
|
||||
|
@ -49,6 +50,7 @@ func trapSignalsCrossPlatform() {
|
|||
for _, f := range OnProcessExit {
|
||||
f() // important cleanup actions only
|
||||
}
|
||||
certmagic.CleanUpOwnLocks()
|
||||
os.Exit(2)
|
||||
}
|
||||
|
||||
|
@ -63,6 +65,7 @@ func trapSignalsCrossPlatform() {
|
|||
}
|
||||
|
||||
go func() {
|
||||
certmagic.CleanUpOwnLocks()
|
||||
os.Exit(executeShutdownCallbacks("SIGINT"))
|
||||
}()
|
||||
}
|
||||
|
|
|
@ -23,6 +23,7 @@ import (
|
|||
"syscall"
|
||||
|
||||
"github.com/mholt/caddy/telemetry"
|
||||
"github.com/mholt/certmagic"
|
||||
)
|
||||
|
||||
// trapSignalsPosix captures POSIX-only signals.
|
||||
|
@ -38,6 +39,7 @@ func trapSignalsPosix() {
|
|||
for _, f := range OnProcessExit {
|
||||
f() // only perform important cleanup actions
|
||||
}
|
||||
certmagic.CleanUpOwnLocks()
|
||||
os.Exit(0)
|
||||
|
||||
case syscall.SIGTERM:
|
||||
|
@ -55,6 +57,7 @@ func trapSignalsPosix() {
|
|||
telemetry.AppendUnique("sigtrap", "SIGTERM")
|
||||
go telemetry.StopEmitting() // won't finish in time, but that's OK - just don't block
|
||||
|
||||
certmagic.CleanUpOwnLocks()
|
||||
os.Exit(exitCode)
|
||||
|
||||
case syscall.SIGUSR1:
|
||||
|
|
Loading…
Reference in a new issue