Commit 6720bdfb authored by Matthew Holt's avatar Matthew Holt

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.
parent 0c626fbc
...@@ -14,7 +14,7 @@ require ( ...@@ -14,7 +14,7 @@ require (
github.com/klauspost/cpuid v1.2.0 github.com/klauspost/cpuid v1.2.0
github.com/kylelemons/godebug v0.0.0-20170820004349-d65d576e9348 // indirect github.com/kylelemons/godebug v0.0.0-20170820004349-d65d576e9348 // indirect
github.com/lucas-clemente/quic-go v0.10.2 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/go-stringutil v0.1.0 // indirect
github.com/naoina/toml v0.1.1 github.com/naoina/toml v0.1.1
github.com/russross/blackfriday v0.0.0-20170610170232-067529f716f4 github.com/russross/blackfriday v0.0.0-20170610170232-067529f716f4
......
...@@ -44,8 +44,8 @@ github.com/lucas-clemente/quic-go v0.10.2/go.mod h1:hvaRS9IHjFLMq76puFJeWNfmn+H7 ...@@ -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 h1:zqEC1GJZFbGZA0tRyNZqRjep92K5fujFtFsu5ZW7Aug=
github.com/lucas-clemente/quic-go-certificates v0.0.0-20160823095156-d2f86524cced/go.mod h1:NCcRLrOTZbzhZvixZLlERbJtDtYsmMw8Jc4vS8Z0g58= 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/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.6.1-0.20190619225040-c7a9fdb17816 h1:DEoTKH/n8k9JXYqM/A3AmW407Q5Rncrkuipqu0mztcg=
github.com/mholt/certmagic v0.5.0/go.mod h1:g4cOPxcjV0oFq3qwpjSA30LReKD8AoIfwAY9VvG35NY= 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 h1:1g0r1IvskvgL8rR+AcHzUA+oFmGcQlaIm4IqakufeMM=
github.com/miekg/dns v1.1.3/go.mod h1:W1PPwlIAgtquWBMBEV9nkV9Cazfe8ScdGz/Lj7v3Nrg= github.com/miekg/dns v1.1.3/go.mod h1:W1PPwlIAgtquWBMBEV9nkV9Cazfe8ScdGz/Lj7v3Nrg=
github.com/naoina/go-stringutil v0.1.0 h1:rCUeRUHjBjGTSHl0VC00jUPLz8/F9dDzYI70Hzifhks= github.com/naoina/go-stringutil v0.1.0 h1:rCUeRUHjBjGTSHl0VC00jUPLz8/F9dDzYI70Hzifhks=
......
...@@ -21,6 +21,7 @@ import ( ...@@ -21,6 +21,7 @@ import (
"sync" "sync"
"github.com/mholt/caddy/telemetry" "github.com/mholt/caddy/telemetry"
"github.com/mholt/certmagic"
) )
// TrapSignals create signal handlers for all applicable signals for this // TrapSignals create signal handlers for all applicable signals for this
...@@ -49,6 +50,7 @@ func trapSignalsCrossPlatform() { ...@@ -49,6 +50,7 @@ func trapSignalsCrossPlatform() {
for _, f := range OnProcessExit { for _, f := range OnProcessExit {
f() // important cleanup actions only f() // important cleanup actions only
} }
certmagic.CleanUpOwnLocks()
os.Exit(2) os.Exit(2)
} }
...@@ -63,6 +65,7 @@ func trapSignalsCrossPlatform() { ...@@ -63,6 +65,7 @@ func trapSignalsCrossPlatform() {
} }
go func() { go func() {
certmagic.CleanUpOwnLocks()
os.Exit(executeShutdownCallbacks("SIGINT")) os.Exit(executeShutdownCallbacks("SIGINT"))
}() }()
} }
......
...@@ -23,6 +23,7 @@ import ( ...@@ -23,6 +23,7 @@ import (
"syscall" "syscall"
"github.com/mholt/caddy/telemetry" "github.com/mholt/caddy/telemetry"
"github.com/mholt/certmagic"
) )
// trapSignalsPosix captures POSIX-only signals. // trapSignalsPosix captures POSIX-only signals.
...@@ -38,6 +39,7 @@ func trapSignalsPosix() { ...@@ -38,6 +39,7 @@ func trapSignalsPosix() {
for _, f := range OnProcessExit { for _, f := range OnProcessExit {
f() // only perform important cleanup actions f() // only perform important cleanup actions
} }
certmagic.CleanUpOwnLocks()
os.Exit(0) os.Exit(0)
case syscall.SIGTERM: case syscall.SIGTERM:
...@@ -55,6 +57,7 @@ func trapSignalsPosix() { ...@@ -55,6 +57,7 @@ func trapSignalsPosix() {
telemetry.AppendUnique("sigtrap", "SIGTERM") telemetry.AppendUnique("sigtrap", "SIGTERM")
go telemetry.StopEmitting() // won't finish in time, but that's OK - just don't block go telemetry.StopEmitting() // won't finish in time, but that's OK - just don't block
certmagic.CleanUpOwnLocks()
os.Exit(exitCode) os.Exit(exitCode)
case syscall.SIGUSR1: case syscall.SIGUSR1:
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment