fix conn tracker memory leak #1056
This commit is contained in:
@@ -554,6 +554,12 @@ func (s *Box) Close() error {
|
|||||||
err = errors.Join(err, closeErr)
|
err = errors.Join(err, closeErr)
|
||||||
s.logger.Trace("close logger completed (", F.Seconds(time.Since(startTime).Seconds()), "s)")
|
s.logger.Trace("close logger completed (", F.Seconds(time.Since(startTime).Seconds()), "s)")
|
||||||
s.logger.Info("sing-box closed (live time: ", F.Seconds(time.Since(s.createdAt).Seconds()), "s)")
|
s.logger.Info("sing-box closed (live time: ", F.Seconds(time.Since(s.createdAt).Seconds()), "s)")
|
||||||
|
if s.statsTracker != nil {
|
||||||
|
s.statsTracker.Reset()
|
||||||
|
}
|
||||||
|
if s.connTracker != nil {
|
||||||
|
s.connTracker.Reset()
|
||||||
|
}
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -29,6 +29,20 @@ func NewConnTracker() *ConnTracker {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (c *ConnTracker) Reset() {
|
||||||
|
c.access.Lock()
|
||||||
|
defer c.access.Unlock()
|
||||||
|
for _, connInfo := range c.connections {
|
||||||
|
if connInfo.Conn != nil {
|
||||||
|
_ = connInfo.Conn.Close()
|
||||||
|
}
|
||||||
|
if connInfo.PacketConn != nil {
|
||||||
|
_ = connInfo.PacketConn.Close()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
c.connections = make(map[string]*ConnectionInfo)
|
||||||
|
}
|
||||||
|
|
||||||
func (c *ConnTracker) generateConnectionID() string {
|
func (c *ConnTracker) generateConnectionID() string {
|
||||||
return uuid.Must(uuid.NewV4()).String()
|
return uuid.Must(uuid.NewV4()).String()
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -34,6 +34,14 @@ func NewStatsTracker() *StatsTracker {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (c *StatsTracker) Reset() {
|
||||||
|
c.access.Lock()
|
||||||
|
defer c.access.Unlock()
|
||||||
|
c.inbounds = make(map[string]Counter)
|
||||||
|
c.outbounds = make(map[string]Counter)
|
||||||
|
c.users = make(map[string]Counter)
|
||||||
|
}
|
||||||
|
|
||||||
func (c *StatsTracker) getReadCounters(inbound string, outbound string, user string) ([]*atomic.Int64, []*atomic.Int64) {
|
func (c *StatsTracker) getReadCounters(inbound string, outbound string, user string) ([]*atomic.Int64, []*atomic.Int64) {
|
||||||
var readCounter []*atomic.Int64
|
var readCounter []*atomic.Int64
|
||||||
var writeCounter []*atomic.Int64
|
var writeCounter []*atomic.Int64
|
||||||
|
|||||||
Reference in New Issue
Block a user