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>
This commit is contained in:
parent
f100d61183
commit
f91c55d6cd
2 changed files with 8 additions and 9 deletions
|
@ -7,6 +7,8 @@ import (
|
||||||
"net/http"
|
"net/http"
|
||||||
pp "net/http/pprof"
|
pp "net/http/pprof"
|
||||||
"runtime"
|
"runtime"
|
||||||
|
|
||||||
|
"github.com/coredns/coredns/plugin/pkg/reuseport"
|
||||||
)
|
)
|
||||||
|
|
||||||
type handler struct {
|
type handler struct {
|
||||||
|
@ -17,7 +19,10 @@ type handler struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h *handler) Startup() error {
|
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 {
|
if err != nil {
|
||||||
log.Errorf("Failed to start pprof handler: %s", err)
|
log.Errorf("Failed to start pprof handler: %s", err)
|
||||||
return err
|
return err
|
||||||
|
|
|
@ -3,7 +3,6 @@ package pprof
|
||||||
import (
|
import (
|
||||||
"net"
|
"net"
|
||||||
"strconv"
|
"strconv"
|
||||||
"sync"
|
|
||||||
|
|
||||||
"github.com/coredns/coredns/plugin"
|
"github.com/coredns/coredns/plugin"
|
||||||
clog "github.com/coredns/coredns/plugin/pkg/log"
|
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.OnStartup(h.Startup)
|
c.OnShutdown(h.Shutdown)
|
||||||
c.OnShutdown(h.Shutdown)
|
|
||||||
})
|
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
var pprofOnce sync.Once
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue