mirror of
https://github.com/SagerNet/sing-box.git
synced 2025-06-13 21:54:13 +08:00
metric-api: http server error handling
This commit is contained in:
parent
3c6173d7f2
commit
7363f49ae3
@ -1,6 +1,8 @@
|
|||||||
package metrics
|
package metrics
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"errors"
|
||||||
|
"net"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
"github.com/sagernet/sing-box/adapter"
|
"github.com/sagernet/sing-box/adapter"
|
||||||
@ -53,12 +55,15 @@ func (s *metricServer) Start() error {
|
|||||||
if !s.opts.Enabled() {
|
if !s.opts.Enabled() {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
go func() {
|
listener, err := net.Listen("tcp", s.opts.Listen)
|
||||||
err := s.http.ListenAndServe()
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
s.logger.Error("metrics api listen error", err)
|
return err
|
||||||
} else {
|
}
|
||||||
s.logger.Info("metrics api listening at ", s.http.Addr, s.opts.Path)
|
s.logger.Info("metrics api listening at ", s.http.Addr, s.opts.Path)
|
||||||
|
go func() {
|
||||||
|
err := s.http.Serve(listener)
|
||||||
|
if err != nil && !errors.Is(err, http.ErrServerClosed) {
|
||||||
|
s.logger.Error("metrics api serve error: ", err)
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
return nil
|
return nil
|
||||||
|
Loading…
x
Reference in New Issue
Block a user