Compare commits

..

5 Commits

Author SHA1 Message Date
patterniha
75c7ccbf78 fix memory leak 2025-08-23 12:37:02 +03:30
patterniha
83ba3c3e54 fix memory leak 2025-08-23 12:28:41 +03:30
patterniha
6af9a6207b fix memory leak 2025-08-23 07:05:08 +03:30
patterniha
42d77f24dc fix 2025-08-23 04:35:02 +03:30
patterniha
b7b364b4af UDP dispatcher: simplified and optimized 2025-08-22 23:47:38 +03:30
2 changed files with 14 additions and 32 deletions

View File

@@ -15,10 +15,9 @@ type ActivityUpdater interface {
type ActivityTimer struct {
sync.RWMutex
updated chan struct{}
checkTask *task.Periodic
onTimeout func()
overridden bool
updated chan struct{}
checkTask *task.Periodic
onTimeout func()
}
func (t *ActivityTimer) Update() {
@@ -32,16 +31,14 @@ func (t *ActivityTimer) check() error {
select {
case <-t.updated:
default:
t.finish(false)
t.finish()
}
return nil
}
func (t *ActivityTimer) finish(locked bool) {
if !locked {
t.Lock()
defer t.Unlock()
}
func (t *ActivityTimer) finish() {
t.Lock()
defer t.Unlock()
if t.onTimeout != nil {
t.onTimeout()
@@ -53,12 +50,9 @@ func (t *ActivityTimer) finish(locked bool) {
}
}
func (t *ActivityTimer) setTimeout(timeout time.Duration) {
if t.onTimeout == nil {
return
}
func (t *ActivityTimer) SetTimeout(timeout time.Duration) {
if timeout == 0 {
t.finish(true)
t.finish()
return
}
@@ -67,26 +61,14 @@ func (t *ActivityTimer) setTimeout(timeout time.Duration) {
Execute: t.check,
}
t.Lock()
if t.checkTask != nil {
t.checkTask.Close()
t.overridden = true
}
t.checkTask = checkTask
t.Update()
common.Must(checkTask.Start())
}
func (t *ActivityTimer) SetTimeout(timeout time.Duration) {
t.Lock()
t.setTimeout(timeout)
t.Unlock()
}
func (t *ActivityTimer) SetTimeoutIfNotOverridden(timeout time.Duration) {
t.Lock()
if !t.overridden {
t.setTimeout(timeout)
}
t.Unlock()
}

View File

@@ -595,10 +595,10 @@ func CopyRawConnIfExist(ctx context.Context, readerConn net.Conn, writerConn net
errors.LogInfo(ctx, "CopyRawConn splice")
statWriter, _ := writer.(*dispatcher.SizeStatWriter)
//runtime.Gosched() // necessary
time.Sleep(time.Millisecond) // without this, there will be a rare ssl error for freedom splice
timer.SetTimeoutIfNotOverridden(24 * time.Hour) // prevent leak, just in case
time.Sleep(time.Millisecond) // without this, there will be a rare ssl error for freedom splice
timer.SetTimeout(8 * time.Hour) // prevent leak, just in case
if inTimer != nil {
inTimer.SetTimeoutIfNotOverridden(24 * time.Hour)
inTimer.SetTimeout(8 * time.Hour)
}
w, err := tc.ReadFrom(readerConn)
if readCounter != nil {