fix(relay): восстановление потоков при отказах turn и занятой квоте

This commit is contained in:
samosvalishe committed 2026-09-12 17:29:09 +03:00
1 parent e72157f4f7
commit 6570cd9dd7
12 files changed
+117 -12

No files matched your search

+10
View File
@@ -12,6 +12,7 @@ import (
"github.com/samosvalishe/free-turn-proxy/internal/provider"
"github.com/samosvalishe/free-turn-proxy/internal/proxy/allocpace"
"github.com/samosvalishe/free-turn-proxy/internal/stats"
"github.com/samosvalishe/free-turn-proxy/internal/transport/turndial"
)
type fakeAuth struct {
@@ -22,6 +23,15 @@ type fakeAuth struct {
dropped atomic.Int32
}
func TestRetryDelayAllocationQuota(t *testing.T) {
for range 100 {
delay := retryDelay(&fakeAuth{}, errors.Join(errors.New("allocate"), turndial.ErrAllocQuota))
if delay < 15*time.Second || delay >= 30*time.Second {
t.Fatalf("quota retry delay = %s", delay)
}
}
}
func (a *fakeAuth) IsAuthError(err error) bool {
return a.authErr != nil && errors.Is(err, a.authErr)
}
+4
View File
@@ -21,6 +21,7 @@ import (
"github.com/samosvalishe/free-turn-proxy/internal/stats"
"github.com/samosvalishe/free-turn-proxy/internal/transport/dtlsdial"
"github.com/samosvalishe/free-turn-proxy/internal/transport/kcpmux"
"github.com/samosvalishe/free-turn-proxy/internal/transport/turndial"
"github.com/samosvalishe/free-turn-proxy/internal/wire"
"github.com/samosvalishe/free-turn-proxy/internal/wire/shape"
"github.com/xtaci/smux"
@@ -324,6 +325,9 @@ func maintainSession(ctx context.Context, deps *Deps, params *Params, peer *net.
// retryDelay: пауза провайдера важнее собственной - ретрай в её середине только продлевает
// локаут и жжёт персону. Джиттер разводит одновременный отказ всех сессий пула.
func retryDelay(auth AuthHandler, err error) time.Duration {
if errors.Is(err, turndial.ErrAllocQuota) {
return time.Duration(15+randx.Intn(15)) * time.Second
}
if errors.Is(err, provider.ErrBackoffActive) {
if until := auth.BackoffUntilUnix(); until > 0 {
if d := time.Until(time.Unix(until, 0)); d > 0 {