fix(udprelay): детект блэкхола permission по логу pion вместо трафик-эвристики
Трафик-watchdog (tx растёт, rx заморожен) ложно рециклил здоровые sender-only стримы: обратный путь WireGuard привязан к endpoint, а не к стриму, поэтому rx==0 на отправляющем стриме — норма, не блэкхол. permWatchFactory считает проваленные циклы refresh permission в логе pion (scope turnc) и закрывает Stream.PermDead после порога. RefreshInterval урезан 120s→30s. oneTURN рециклит allocation по PermDead.
This commit is contained in:
1 parent
410abb73e9
commit
106a48533c
4 files changed
+188
-48
No files matched your search
@@ -0,0 +1,72 @@
|
||||
package turndial
|
||||
|
||||
import (
|
||||
"sync/atomic"
|
||||
"testing"
|
||||
|
||||
"github.com/pion/logging"
|
||||
)
|
||||
|
||||
func newTestWatch(threshold int) (*permWatchFactory, *atomic.Int32) {
|
||||
var fired atomic.Int32
|
||||
f := &permWatchFactory{
|
||||
inner: logging.NewDefaultLoggerFactory(),
|
||||
threshold: threshold,
|
||||
onDead: func() { fired.Add(1) },
|
||||
}
|
||||
return f, &fired
|
||||
}
|
||||
|
||||
func TestPermWatchFiresAfterThreshold(t *testing.T) {
|
||||
f, fired := newTestWatch(2)
|
||||
log := f.NewLogger(turncScope)
|
||||
|
||||
log.Warnf(permFailMarker+": %s", "boom")
|
||||
if fired.Load() != 0 {
|
||||
t.Fatalf("fired too early after 1 fail: %d", fired.Load())
|
||||
}
|
||||
log.Warnf(permFailMarker+": %s", "boom")
|
||||
if fired.Load() != 1 {
|
||||
t.Fatalf("expected 1 fire after threshold, got %d", fired.Load())
|
||||
}
|
||||
// Дальнейшие провалы не должны фаерить повторно.
|
||||
log.Warnf(permFailMarker+": %s", "boom")
|
||||
if fired.Load() != 1 {
|
||||
t.Fatalf("fired more than once: %d", fired.Load())
|
||||
}
|
||||
}
|
||||
|
||||
func TestPermWatchResetOnSuccess(t *testing.T) {
|
||||
f, fired := newTestWatch(2)
|
||||
log := f.NewLogger(turncScope)
|
||||
|
||||
log.Warnf(permFailMarker + ": x")
|
||||
log.Debug(permOKMarker) // сброс счётчика
|
||||
log.Warnf(permFailMarker + ": x")
|
||||
if fired.Load() != 0 {
|
||||
t.Fatalf("reset failed: fired=%d (fail/ok/fail не должно фаерить)", fired.Load())
|
||||
}
|
||||
}
|
||||
|
||||
func TestPermWatchIgnoresOtherScopes(t *testing.T) {
|
||||
f, fired := newTestWatch(1)
|
||||
log := f.NewLogger("other")
|
||||
if _, ok := log.(*permWatchLogger); ok {
|
||||
t.Fatal("non-turnc scope must not be wrapped")
|
||||
}
|
||||
log.Warnf(permFailMarker)
|
||||
if fired.Load() != 0 {
|
||||
t.Fatalf("fired on non-turnc scope: %d", fired.Load())
|
||||
}
|
||||
}
|
||||
|
||||
func TestPermWatchIgnoresUnrelatedMessages(t *testing.T) {
|
||||
f, fired := newTestWatch(1)
|
||||
log := f.NewLogger(turncScope)
|
||||
log.Debug("Started refresh permission timer")
|
||||
log.Debug("No permission to refresh")
|
||||
log.Warnf("Failed to refresh allocation: %s", "x")
|
||||
if fired.Load() != 0 {
|
||||
t.Fatalf("fired on unrelated message: %d", fired.Load())
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user