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