fix: отбрасывать опоздавший повтор client id, общий backoff квоты

This commit is contained in:
samosvalishe committed 2026-09-22 00:43:06 +03:00
1 parent 1e3782c546
commit 05bbe996c1
5 files changed
+12 -12

No files matched your search

+2 -4
View File
@@ -295,15 +295,13 @@ func AcceptClientID(conn net.Conn, authorize func(id string, mode byte) error) (
type ackedConn struct {
net.Conn
rec []byte
data bool
rec []byte
}
func (c *ackedConn) Read(b []byte) (int, error) {
for {
n, err := c.Conn.Read(b)
if err != nil || c.data || !bytes.Equal(b[:n], c.rec) {
c.data = c.data || err == nil
if err != nil || !bytes.Equal(b[:n], c.rec) {
return n, err
}
if _, err := c.Write([]byte{idAck}); err != nil {
+1 -1
View File
@@ -313,7 +313,7 @@ func maintainSession(ctx context.Context, deps *Deps, params *Params, peer *net.
// локаут и жжёт персону. Джиттер разводит одновременный отказ всех сессий пула.
func retryDelay(auth AuthHandler, err error) time.Duration {
if errors.Is(err, turndial.ErrAllocQuota) {
return time.Duration(15+randx.Intn(15)) * time.Second
return turndial.QuotaBackoff()
}
if errors.Is(err, provider.ErrBackoffActive) {
if until := auth.BackoffUntilUnix(); until > 0 {
+1 -5
View File
@@ -23,9 +23,6 @@ import (
var errPairRecycled = errors.New("udprelay: stream pair recycled")
const (
quotaBackoff = 15 * time.Second
quotaBackoffJitter = 15 * time.Second
pipeBufLimit = 256 << 10
)
@@ -95,9 +92,8 @@ func TURNLoop(ctx context.Context, deps *Deps, params *Params, peer *net.UDPAddr
deps.fatal(err)
return
}
// Квота может оставаться занятой после deallocate.
if errors.Is(err, turndial.ErrAllocQuota) {
wait := quotaBackoff + time.Duration(randx.Intn(int(quotaBackoffJitter/time.Second)))*time.Second
wait := turndial.QuotaBackoff()
deps.log().Warnf("[STREAM %d] квота аллокаций занята - пауза %s", streamID, wait)
select {
case <-ctx.Done():
+4 -2
View File
@@ -55,8 +55,10 @@ func Fetch(ctx context.Context, url string) (*Sub, error) {
dialer := dnsdial.AppDialer(dnsdial.DNSModeAuto)
// Клон DefaultTransport, а не пустой: иначе теряются системный прокси и таймауты TLS.
tr, _ := http.DefaultTransport.(*http.Transport)
tr = tr.Clone()
tr := &http.Transport{}
if dt, ok := http.DefaultTransport.(*http.Transport); ok {
tr = dt.Clone()
}
tr.DialContext = dialer.DialContext
client := &http.Client{Transport: tr}
resp, err := client.Do(req)
+4
View File
@@ -21,6 +21,10 @@ import (
// аллокаций. Лечится ожиданием, а не сменой реквизитов (см. IsAuthError в vkauth).
var ErrAllocQuota = errors.New("turndial: allocation quota reached")
func QuotaBackoff() time.Duration {
return time.Duration(15+randx.Intn(15)) * time.Second
}
// Config задаёт параметры подключения к TURN-серверу.
type Config struct {
HostOverride string