update code for ensuring session stay alive to prevent crash

This commit is contained in:
Dario 2020-10-07 11:17:58 +02:00
parent 7f2ff630a9
commit b2f0545f06
5 changed files with 25 additions and 17 deletions

View File

@ -73,6 +73,8 @@ Poco::Data::Session ConnectionManager::getConnection(ConnectionType type)
throw Poco::NotFoundException("Connection Type unknown", std::to_string(type));
}
auto session = mSessionPools.getPool(mSessionPoolNames[type]).get();
//return mSessionPoolNames[type];
/*if (!session.isConnected()) {
printf("reconnect called\n");
try {

View File

@ -47,6 +47,7 @@ private:
std::string mSessionPoolNames[CONNECTION_MAX];
Poco::Data::SessionPoolContainer mSessionPools;
Poco::FastMutex mWorkingMutex;
};
#endif //GRADIDO_LOGIN_SERVER_SINGLETON_MANAGER_CONNECTION_MANAGER_INCLUDE

View File

@ -787,15 +787,15 @@ UserStates Session::loadUser(const std::string& email, const std::string& passwo
}
}
//Profiler usedTime;
printf("before lock\n");
//printf("before lock\n");
lock(functionName);
printf("locked \n");
//printf("locked \n");
if (!mSessionUser.isNull() && mSessionUser->getEmail() != email) {
mSessionUser.assign(nullptr);
mNewUser.assign(nullptr);
printf("user nullptr assigned\n");
//printf("user nullptr assigned\n");
}
printf("after checking if session user is null\n");
//printf("after checking if session user is null\n");
//if (!mSessionUser) {
if (mNewUser.isNull()) {
printf("new user is null\n");
@ -809,14 +809,14 @@ UserStates Session::loadUser(const std::string& email, const std::string& passwo
printf("user loaded from email\n");
}
printf("before get model\n");
//printf("before get model\n");
auto user_model = mNewUser->getModel();
if (user_model && user_model->isDisabled()) {
return USER_DISABLED;
}
printf("before if login\n");
//printf("before if login\n");
if (!mSessionUser.isNull() && mSessionUser->getUserState() >= USER_LOADED_FROM_DB) {
printf("before login\n");
//printf("before login\n");
int loginResult = 0;
int exitCount = 0;
do {
@ -840,7 +840,7 @@ UserStates Session::loadUser(const std::string& email, const std::string& passwo
return USER_PASSWORD_ENCRYPTION_IN_PROCESS;
}
printf("new user login with result: %d\n", loginResult);
//printf("new user login with result: %d\n", loginResult);
if (-1 == loginResult) {
addError(new Error(functionName, "error in user data set, saved pubkey didn't match extracted pubkey from private key"));
@ -882,14 +882,14 @@ UserStates Session::loadUser(const std::string& email, const std::string& passwo
// can be removed if session user isn't used any more
// don't calculate password two times anymore
mSessionUser->login(mNewUser);
printf("after old user login\n");
//printf("after old user login\n");
/*if (mNewUser->getModel()->getPasswordHashed() && !mSessionUser->validatePwd(password, this)) {
unlock();
return USER_PASSWORD_INCORRECT;
}*/
}
else {
printf("before sleep\n");
//printf("before sleep\n");
User::fakeCreateCryptoKey();
}
@ -903,10 +903,10 @@ UserStates Session::loadUser(const std::string& email, const std::string& passwo
unlock();
return false;
}*/
printf("before detect session state\n");
//printf("before detect session state\n");
detectSessionState();
unlock();
printf("before return user state\n");
//printf("before return user state\n");
return mSessionUser->getUserState();
}

View File

@ -43,7 +43,8 @@ namespace model {
//printf("ModelBase::insertIntoDB with table: %s\n", getTableName());
auto cm = ConnectionManager::getInstance();
Poco::ScopedLock<Poco::Mutex> _lock(mWorkMutex);
Poco::Data::Statement insert = _insertIntoDB(cm->getConnection(CONNECTION_MYSQL_LOGIN_SERVER));
auto session = cm->getConnection(CONNECTION_MYSQL_LOGIN_SERVER);
Poco::Data::Statement insert = _insertIntoDB(session);
size_t resultCount = 0;
try {

View File

@ -78,7 +78,8 @@ namespace model {
{
auto cm = ConnectionManager::getInstance();
Poco::ScopedLock<Poco::Mutex> _lock(mWorkMutex);
Poco::Data::Statement select = _loadFromDB(cm->getConnection(CONNECTION_MYSQL_LOGIN_SERVER), fieldName);
auto session = cm->getConnection(CONNECTION_MYSQL_LOGIN_SERVER);
Poco::Data::Statement select = _loadFromDB(session, fieldName);
select, Poco::Data::Keywords::useRef(fieldValue);
size_t resultCount = 0;
@ -129,7 +130,8 @@ namespace model {
results.reserve(expectedResults);
}
auto cm = ConnectionManager::getInstance();
Poco::Data::Statement select = _loadMultipleFromDB(cm->getConnection(CONNECTION_MYSQL_LOGIN_SERVER), fieldName);
auto session = cm->getConnection(CONNECTION_MYSQL_LOGIN_SERVER);
Poco::Data::Statement select = _loadMultipleFromDB(session, fieldName);
select, Poco::Data::Keywords::into(results), Poco::Data::Keywords::useRef(fieldValue);
size_t resultCount = 0;
@ -160,7 +162,8 @@ namespace model {
results.reserve(expectedResults);
}
auto cm = ConnectionManager::getInstance();
Poco::Data::Statement select = _loadMultipleFromDB(cm->getConnection(CONNECTION_MYSQL_LOGIN_SERVER), fieldNames, conditionType);
auto session = cm->getConnection(CONNECTION_MYSQL_LOGIN_SERVER);
Poco::Data::Statement select = _loadMultipleFromDB(session, fieldNames, conditionType);
select, Poco::Data::Keywords::into(results);// Poco::Data::Keywords::useRef(fieldValue);
for (auto it = fieldValues.begin(); it != fieldValues.end(); it++) {
select, Poco::Data::Keywords::useRef(*it);
@ -186,7 +189,8 @@ namespace model {
{
auto cm = ConnectionManager::getInstance();
Poco::ScopedLock<Poco::Mutex> _lock(mWorkMutex);
Poco::Data::Statement select = _loadFromDB(cm->getConnection(CONNECTION_MYSQL_LOGIN_SERVER), fieldNames, conditionType);
auto session = cm->getConnection(CONNECTION_MYSQL_LOGIN_SERVER);
Poco::Data::Statement select = _loadFromDB(session, fieldNames, conditionType);
select, Poco::Data::Keywords::useRef(field1Value), Poco::Data::Keywords::useRef(field2Value);
size_t resultCount = 0;