Commit e55fbfe422a2721a0f056bc6a86f921748d985f1
1 parent
78dcaba6
Don't hold two locks while expiring sessions
Showing
1 changed file
with
10 additions
and
2 deletions
subscriptionstore.cpp
| ... | ... | @@ -665,6 +665,9 @@ void SubscriptionStore::removeExpiredSessionsClients() |
| 665 | 665 | const std::chrono::time_point<std::chrono::steady_clock> now = std::chrono::steady_clock::now(); |
| 666 | 666 | const std::chrono::seconds secondsSinceEpoch = std::chrono::duration_cast<std::chrono::seconds>(now.time_since_epoch()); |
| 667 | 667 | |
| 668 | + // Collect sessions to remove for a separate step, to avoid holding two locks at the same time. | |
| 669 | + std::vector<std::shared_ptr<Session>> sessionsToRemove; | |
| 670 | + | |
| 668 | 671 | int removedSessions = 0; |
| 669 | 672 | int processedRemovals = 0; |
| 670 | 673 | int queuedRemovalsLeft = -1; |
| ... | ... | @@ -693,8 +696,7 @@ void SubscriptionStore::removeExpiredSessionsClients() |
| 693 | 696 | // A session could have been picked up again, so we have to verify its expiration status. |
| 694 | 697 | if (lockedSession && !lockedSession->hasActiveClient()) |
| 695 | 698 | { |
| 696 | - removeSession(lockedSession); | |
| 697 | - removedSessions++; | |
| 699 | + sessionsToRemove.push_back(lockedSession); | |
| 698 | 700 | } |
| 699 | 701 | } |
| 700 | 702 | it = queuedSessionRemovals.erase(it); |
| ... | ... | @@ -705,6 +707,12 @@ void SubscriptionStore::removeExpiredSessionsClients() |
| 705 | 707 | queuedRemovalsLeft = queuedSessionRemovals.size(); |
| 706 | 708 | } |
| 707 | 709 | |
| 710 | + for(std::shared_ptr<Session> &session : sessionsToRemove) | |
| 711 | + { | |
| 712 | + removeSession(session); | |
| 713 | + removedSessions++; | |
| 714 | + } | |
| 715 | + | |
| 708 | 716 | logger->logf(LOG_DEBUG, "Processed %d queued session removals, resulting in %d deleted expired sessions. %d queued removals in the future.", |
| 709 | 717 | processedRemovals, removedSessions, queuedRemovalsLeft); |
| 710 | 718 | ... | ... |