Fix the session bug introduced in PR #523 (#528)

This commit is contained in:
An Tao 2020-08-06 19:35:30 +08:00 committed by GitHub
parent 80a8f62e30
commit fda2719dd4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 8 additions and 10 deletions

View File

@ -188,6 +188,7 @@ class Session
{
std::lock_guard<std::mutex> lck(mutex_);
sessionId_ = id;
needToChange_ = false;
}
};

View File

@ -71,14 +71,11 @@ void SessionManager::changeSessionId(const SessionPtr &sessionPtr)
auto oldId = sessionPtr->sessionId();
auto newId = utils::getUuid();
sessionPtr->setSessionId(newId);
{
std::lock_guard<std::mutex> lock(mapMutex_);
// For requests sent before setting the new session ID to the client, we
// reserve the old session slot for a period of time.
sessionMapPtr_->runAfter(10, [this, oldId = std::move(oldId)]() {
LOG_TRACE << "remove the old slot of the session";
sessionMapPtr_->erase(oldId);
});
sessionMapPtr_->insert(newId, sessionPtr, timeout_);
}
sessionMapPtr_->insert(newId, sessionPtr, timeout_);
// For requests sent before setting the new session ID to the client, we
// reserve the old session slot for a period of time.
sessionMapPtr_->runAfter(10, [this, oldId = std::move(oldId)]() {
LOG_TRACE << "remove the old slot of the session";
sessionMapPtr_->erase(oldId);
});
}