do not panic if pprof initialization fails

This commit is contained in:
aler9
2020-08-30 14:10:05 +02:00
parent 833ce34838
commit 01b2e741b2
3 changed files with 55 additions and 23 deletions

29
main.go
View File

@@ -5,8 +5,6 @@ import (
"io"
"log"
"net"
"net/http"
_ "net/http/pprof"
"os"
"time"
@@ -17,10 +15,6 @@ import (
var Version = "v0.0.0"
const (
pprofAddress = ":9999"
)
type logDestination int
const (
@@ -165,6 +159,7 @@ type program struct {
conf *conf
logFile *os.File
metrics *metrics
pprof *pprof
serverRtsp *serverTcp
serverRtp *serverUdp
serverRtcp *serverUdp
@@ -238,14 +233,10 @@ func newProgram(args []string, stdin io.Reader) (*program, error) {
}
if conf.Pprof {
go func(mux *http.ServeMux) {
p.log("[pprof] opened on " + pprofAddress)
panic((&http.Server{
Addr: pprofAddress,
Handler: mux,
}).ListenAndServe())
}(http.DefaultServeMux)
http.DefaultServeMux = http.NewServeMux()
p.pprof, err = newPprof(p)
if err != nil {
return nil, err
}
}
if _, ok := conf.protocolsParsed[gortsplib.StreamProtocolUdp]; ok {
@@ -269,17 +260,21 @@ func newProgram(args []string, stdin io.Reader) (*program, error) {
go p.metrics.run()
}
if p.pprof != nil {
go p.pprof.run()
}
if _, ok := conf.protocolsParsed[gortsplib.StreamProtocolUdp]; ok {
go p.serverRtp.run()
go p.serverRtcp.run()
}
go p.serverRtsp.run()
for _, s := range p.sources {
go s.run()
}
go p.serverRtsp.run()
for _, p := range p.paths {
p.onInit()
}
@@ -629,7 +624,7 @@ func (p *program) forwardFrame(path string, trackId int, streamType gortsplib.St
func main() {
_, err := newProgram(os.Args[1:], os.Stdin)
if err != nil {
log.Fatal("ERR:", err)
log.Fatal("ERR: ", err)
}
select {}