From 5b6ac183321bcba27d4890a8a9d30854293d9e0e Mon Sep 17 00:00:00 2001 From: samosvalishe Date: Tue, 22 Sep 2026 20:04:05 +0300 Subject: [PATCH] =?UTF-8?q?perf(tcp):=20=D1=81=D0=BC=D0=B5=D1=80=D1=82?= =?UTF-8?q?=D1=8C=20smux-=D1=81=D0=B5=D1=81=D1=81=D0=B8=D0=B8=20=D0=B1?= =?UTF-8?q?=D0=B5=D0=B7=20=D0=BF=D0=BE=D0=BB=D0=BB=D0=B8=D0=BD=D0=B3=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- internal/proxy/tcprelay/session_test.go | 4 ++++ internal/proxy/tcprelay/tcprelay.go | 23 ++++++++--------------- 2 files changed, 12 insertions(+), 15 deletions(-) diff --git a/internal/proxy/tcprelay/session_test.go b/internal/proxy/tcprelay/session_test.go index cee9b9a..1ccd1db 100644 --- a/internal/proxy/tcprelay/session_test.go +++ b/internal/proxy/tcprelay/session_test.go @@ -191,9 +191,13 @@ func TestAwaitDeadOnClosedSession(t *testing.T) { s := &session{smux: sess, permDead: make(chan struct{})} _ = sess.Close() + start := time.Now() if !awaitDead(context.Background(), logx.Nop(), s, 1) { t.Error("awaitDead() = false on closed smux, want true") } + if d := time.Since(start); d > 100*time.Millisecond { + t.Errorf("awaitDead() noticed close after %s, want immediately", d) + } } // Рецикл рвёт сессии, но состав пула не трогает: их переподнимает maintainSession. diff --git a/internal/proxy/tcprelay/tcprelay.go b/internal/proxy/tcprelay/tcprelay.go index 65ad57a..7867203 100644 --- a/internal/proxy/tcprelay/tcprelay.go +++ b/internal/proxy/tcprelay/tcprelay.go @@ -31,7 +31,6 @@ const ( setupRetryJitter = 4 * time.Second providerBackoffDelay = 60 * time.Second reconnectDelay = 2 * time.Second - sessionPollDelay = time.Second minAcceptBackoff = 5 * time.Millisecond maxAcceptBackoff = time.Second ) @@ -330,20 +329,14 @@ func retryDelay(auth AuthHandler, err error) time.Duration { // awaitDead: false - вышли по отмене ctx, а не по смерти сессии. func awaitDead(ctx context.Context, log logx.Logger, s *session, id int) bool { - t := time.NewTicker(sessionPollDelay) - defer t.Stop() - for { - select { - case <-ctx.Done(): - return false - case <-s.permDead: - log.Warnf("[session %d] TURN channel-bind умер - рецикл allocation", id) - return true - case <-t.C: - if s.smux.IsClosed() { - return true - } - } + select { + case <-ctx.Done(): + return false + case <-s.permDead: + log.Warnf("[session %d] TURN channel-bind умер - рецикл allocation", id) + return true + case <-s.smux.CloseChan(): + return true } }