Browse Source

fix stats server blocking

pull/15/head
Jason 5 years ago
parent
commit
5c3c821db5
  1. 7
      cmd/main.go
  2. 5
      cmd/main_stats.go
  3. 3
      common/stats/session/session.go

7
cmd/main.go

@ -70,13 +70,6 @@ func addPostFlagsInitFn(fn func()) {
postFlagsInitFn = append(postFlagsInitFn, fn)
}
func registerHandlerCreator(creator func()) {
if handlerCreator != nil {
log.Fatalf("handlerCreator can only register once")
}
handlerCreator = creator
}
func init() {
// Main
args.Version = flag.Bool("version", false, "Print version")

5
cmd/main_stats.go

@ -5,7 +5,6 @@ package main
import (
"flag"
"github.com/xjasonlyu/tun2socks/common/log"
"github.com/xjasonlyu/tun2socks/common/stats/session"
)
@ -22,9 +21,7 @@ func init() {
session.StatsVersion = version
// start session stater
if err := sessionStater.Start(); err != nil {
log.Fatalf("start session stater failed: %v", err)
}
sessionStater.Start()
} else {
sessionStater = nil
}

3
common/stats/session/session.go

@ -96,7 +96,8 @@ func (s *simpleSessionStater) Start() error {
})
mux.HandleFunc(StatsPath, sessionStatsHandler)
s.server = &http.Server{Addr: StatsAddr, Handler: mux}
return s.server.ListenAndServe()
go s.server.ListenAndServe()
return nil
}
func (s *simpleSessionStater) Stop() error {

Loading…
Cancel
Save