()
| 407 | } |
| 408 | |
| 409 | func (m *Manager) cleanup() { |
| 410 | cutoff := time.Now().Add(-m.expiry) |
| 411 | m.mu.Lock() |
| 412 | defer m.mu.Unlock() |
| 413 | for id, sess := range m.sessions { |
| 414 | sess.mu.Lock() |
| 415 | pinned := sess.BridgePinned |
| 416 | expired := sess.LastActivity.Before(cutoff) |
| 417 | sess.mu.Unlock() |
| 418 | if pinned { |
| 419 | continue // bridge-registered sessions are never expired |
| 420 | } |
| 421 | if expired { |
| 422 | // Close all subscriber and observer channels before removing. |
| 423 | sess.mu.Lock() |
| 424 | for subID, ch := range sess.subscribers { |
| 425 | close(ch) |
| 426 | delete(sess.subscribers, subID) |
| 427 | } |
| 428 | for subID, ch := range sess.observers { |
| 429 | close(ch) |
| 430 | delete(sess.observers, subID) |
| 431 | } |
| 432 | sess.mu.Unlock() |
| 433 | delete(m.sessions, id) |
| 434 | } |
| 435 | } |
| 436 | } |
| 437 | |
| 438 | func hashKey(apiKey string) string { |
| 439 | b := make([]byte, 16) |
no outgoing calls
no test coverage detected