Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix reloading in plugin/pprof. #3454

Merged
merged 3 commits into from Nov 18, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 6 additions & 1 deletion plugin/pprof/pprof.go
Expand Up @@ -7,6 +7,8 @@ import (
"net/http"
pp "net/http/pprof"
"runtime"

"github.com/coredns/coredns/plugin/pkg/reuseport"
)

type handler struct {
Expand All @@ -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
Expand Down
10 changes: 2 additions & 8 deletions plugin/pprof/setup.go
Expand Up @@ -3,7 +3,6 @@ package pprof
import (
"net"
"strconv"
"sync"

"github.com/coredns/coredns/plugin"
clog "github.com/coredns/coredns/plugin/pkg/log"
Expand Down Expand Up @@ -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