Skip to content

Commit 8c93ce2

Browse files
authored
fix: increase sleep duration to 50ms in various loops for improved stability
1 parent 3d2f09f commit 8c93ce2

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

internal/common.go

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -345,6 +345,7 @@ func (c *Common) commonQueue() error {
345345
case c.signalChan <- signal:
346346
default:
347347
c.logger.Debug("Queue limit reached: %v", semaphoreLimit)
348+
time.Sleep(50 * time.Millisecond)
348349
}
349350
}
350351
}
@@ -361,7 +362,7 @@ func (c *Common) healthCheck() error {
361362
default:
362363
// 尝试获取锁
363364
if !c.mu.TryLock() {
364-
time.Sleep(time.Millisecond)
365+
time.Sleep(50 * time.Millisecond)
365366
continue
366367
}
367368

@@ -406,7 +407,7 @@ func (c *Common) commonLoop() {
406407
go c.commonUDPLoop()
407408
return
408409
}
409-
time.Sleep(time.Millisecond)
410+
time.Sleep(50 * time.Millisecond)
410411
}
411412
}
412413
}
@@ -421,6 +422,8 @@ func (c *Common) commonTCPLoop() {
421422
// 接受来自目标的TCP连接
422423
targetConn, err := c.targetListener.Accept()
423424
if err != nil {
425+
c.logger.Error("Accept failed: %v", err)
426+
time.Sleep(50 * time.Millisecond)
424427
continue
425428
}
426429

@@ -495,6 +498,8 @@ func (c *Common) commonUDPLoop() {
495498
// 读取来自目标的UDP数据
496499
n, clientAddr, err := c.targetUDPConn.ReadFromUDP(buffer)
497500
if err != nil {
501+
c.logger.Error("ReadFromUDP failed: %v", err)
502+
time.Sleep(50 * time.Millisecond)
498503
continue
499504
}
500505

@@ -612,7 +617,7 @@ func (c *Common) commonOnce() error {
612617
for {
613618
// 等待连接池准备就绪
614619
if !c.tunnelPool.Ready() {
615-
time.Sleep(time.Millisecond)
620+
time.Sleep(50 * time.Millisecond)
616621
continue
617622
}
618623

@@ -879,7 +884,7 @@ func (c *Common) singleTCPLoop() error {
879884
targetConn := c.tunnelPool.ClientGet("")
880885
if targetConn == nil {
881886
c.logger.Error("Get failed: no target connection available")
882-
time.Sleep(100 * time.Millisecond)
887+
time.Sleep(50 * time.Millisecond)
883888
return
884889
}
885890

0 commit comments

Comments
 (0)