perf(tcp): смерть smux-сессии без поллинга
This commit is contained in:
1 parent
b0e3cfe20a
commit
5b6ac18332
2 files changed
+12
-15
No files matched your search
@@ -191,9 +191,13 @@ func TestAwaitDeadOnClosedSession(t *testing.T) {
|
|||||||
s := &session{smux: sess, permDead: make(chan struct{})}
|
s := &session{smux: sess, permDead: make(chan struct{})}
|
||||||
_ = sess.Close()
|
_ = sess.Close()
|
||||||
|
|
||||||
|
start := time.Now()
|
||||||
if !awaitDead(context.Background(), logx.Nop(), s, 1) {
|
if !awaitDead(context.Background(), logx.Nop(), s, 1) {
|
||||||
t.Error("awaitDead() = false on closed smux, want true")
|
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.
|
// Рецикл рвёт сессии, но состав пула не трогает: их переподнимает maintainSession.
|
||||||
|
|||||||
@@ -31,7 +31,6 @@ const (
|
|||||||
setupRetryJitter = 4 * time.Second
|
setupRetryJitter = 4 * time.Second
|
||||||
providerBackoffDelay = 60 * time.Second
|
providerBackoffDelay = 60 * time.Second
|
||||||
reconnectDelay = 2 * time.Second
|
reconnectDelay = 2 * time.Second
|
||||||
sessionPollDelay = time.Second
|
|
||||||
minAcceptBackoff = 5 * time.Millisecond
|
minAcceptBackoff = 5 * time.Millisecond
|
||||||
maxAcceptBackoff = time.Second
|
maxAcceptBackoff = time.Second
|
||||||
)
|
)
|
||||||
@@ -330,20 +329,14 @@ func retryDelay(auth AuthHandler, err error) time.Duration {
|
|||||||
|
|
||||||
// awaitDead: false - вышли по отмене ctx, а не по смерти сессии.
|
// awaitDead: false - вышли по отмене ctx, а не по смерти сессии.
|
||||||
func awaitDead(ctx context.Context, log logx.Logger, s *session, id int) bool {
|
func awaitDead(ctx context.Context, log logx.Logger, s *session, id int) bool {
|
||||||
t := time.NewTicker(sessionPollDelay)
|
select {
|
||||||
defer t.Stop()
|
case <-ctx.Done():
|
||||||
for {
|
return false
|
||||||
select {
|
case <-s.permDead:
|
||||||
case <-ctx.Done():
|
log.Warnf("[session %d] TURN channel-bind умер - рецикл allocation", id)
|
||||||
return false
|
return true
|
||||||
case <-s.permDead:
|
case <-s.smux.CloseChan():
|
||||||
log.Warnf("[session %d] TURN channel-bind умер - рецикл allocation", id)
|
return true
|
||||||
return true
|
|
||||||
case <-t.C:
|
|
||||||
if s.smux.IsClosed() {
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user