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

chore: Add a global config to enable pprof #532

Merged
merged 2 commits into from
Jun 16, 2024
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions cmd/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ import (
"github.com/daeuniverse/outbound/protocol/direct"
"gopkg.in/natefinch/lumberjack.v2"

_ "net/http/pprof"

"github.com/daeuniverse/dae/cmd/internal"
"github.com/daeuniverse/dae/common"
"github.com/daeuniverse/dae/common/consts"
Expand Down Expand Up @@ -124,6 +126,13 @@ func Run(log *logrus.Logger, conf *config.Config, externGeoDataDirs []string) (e
return err
}

var pprofServer *http.Server
if conf.Global.PprofPort != 0 {
pprofAddr := fmt.Sprintf("localhost:%d", conf.Global.PprofPort)
pprofServer = &http.Server{Addr: pprofAddr, Handler: nil}
go pprofServer.ListenAndServe()
}

// Serve tproxy TCP/UDP server util signals.
var listener *control.Listener
sigs := make(chan os.Signal, 1)
Expand Down Expand Up @@ -277,6 +286,16 @@ loop:
oldC.AbortConnections()
}
oldC.Close()

if pprofServer != nil {
pprofServer.Shutdown(context.Background())
pprofServer = nil
}
if newConf.Global.PprofPort != 0 {
pprofAddr := fmt.Sprintf("localhost:%d", conf.Global.PprofPort)
pprofServer = &http.Server{Addr: pprofAddr, Handler: nil}
go pprofServer.ListenAndServe()
}
case syscall.SIGHUP:
// Ignore.
continue
Expand Down
1 change: 1 addition & 0 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ type Global struct {
SniffingTimeout time.Duration `mapstructure:"sniffing_timeout" default:"100ms"`
TlsImplementation string `mapstructure:"tls_implementation" default:"tls"`
UtlsImitate string `mapstructure:"utls_imitate" default:"chrome_auto"`
PprofPort uint16 `mapstructure:"pprof_port" default:"0"`
}

type Utls struct {
Expand Down
3 changes: 3 additions & 0 deletions example.dae
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ global {
# iptables tproxy rules.
tproxy_port_protect: true

# Set non-zero value to enable pprof.
pprof_port: 0

# If not zero, traffic sent from dae will be set SO_MARK. It is useful to avoid traffic loop with iptables tproxy
# rules.
so_mark_from_dae: 0
Expand Down
Loading