aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Gonzalo Paniagua Javier <gonzalo.mono@gmail.com> 2019-11-17 23:58:00 -0800
committerGravatar Miek Gieben <miek@miek.nl> 2019-11-18 07:58:00 +0000
commitf91c55d6cdf81f56707d0ee6b47f50d164555d68 (patch)
tree155d454e8b89d65e9b1cd8acb16deb937822f6e8
parentf100d6118340edb68197af7a83e90fb232af70a8 (diff)
downloadcoredns-f91c55d6cdf81f56707d0ee6b47f50d164555d68.tar.gz
coredns-f91c55d6cdf81f56707d0ee6b47f50d164555d68.tar.zst
coredns-f91c55d6cdf81f56707d0ee6b47f50d164555d68.zip
Fix reloading in plugin/pprof. (#3454)
* Fix reloading in plugin/pprof. Reloading the server without changing the listen address results in an error because Startup is called for newly set up plugins before Shutdown is called for the old ones. Signed-off-by: Gonzalo Paniagua Javier <gonzalo.mono@gmail.com> * Use pkg/reuseport when listening. Use coredns' newly added reuseport. Signed-off-by: Gonzalo Paniagua Javier <gonzalo.mono@gmail.com> * Revert go.{mod,sum} changes. Signed-off-by: Gonzalo Paniagua Javier <gonzalo.mono@gmail.com>
-rw-r--r--plugin/pprof/pprof.go7
-rw-r--r--plugin/pprof/setup.go10
2 files changed, 8 insertions, 9 deletions
diff --git a/plugin/pprof/pprof.go b/plugin/pprof/pprof.go
index c53010089..ddf5ab2df 100644
--- a/plugin/pprof/pprof.go
+++ b/plugin/pprof/pprof.go
@@ -7,6 +7,8 @@ import (
"net/http"
pp "net/http/pprof"
"runtime"
+
+ "github.com/coredns/coredns/plugin/pkg/reuseport"
)
type handler struct {
@@ -17,7 +19,10 @@ type handler struct {
}
func (h *handler) Startup() error {
- ln, err := net.Listen("tcp", h.addr)
+ // Reloading the plugin without changing the listening address results
+ // in an error unless we reuse the port because Startup is called for
+ // new handlers before Shutdown is called for the old ones.
+ ln, err := reuseport.Listen("tcp", h.addr)
if err != nil {
log.Errorf("Failed to start pprof handler: %s", err)
return err
diff --git a/plugin/pprof/setup.go b/plugin/pprof/setup.go
index 8de3b2ac0..a9b93673c 100644
--- a/plugin/pprof/setup.go
+++ b/plugin/pprof/setup.go
@@ -3,7 +3,6 @@ package pprof
import (
"net"
"strconv"
- "sync"
"github.com/coredns/coredns/plugin"
clog "github.com/coredns/coredns/plugin/pkg/log"
@@ -62,12 +61,7 @@ func setup(c *caddy.Controller) error {
}
- pprofOnce.Do(func() {
- c.OnStartup(h.Startup)
- c.OnShutdown(h.Shutdown)
- })
-
+ c.OnStartup(h.Startup)
+ c.OnShutdown(h.Shutdown)
return nil
}
-
-var pprofOnce sync.Once