diff --git a/orm_lib/src/DbClientLockFree.cc b/orm_lib/src/DbClientLockFree.cc index 62edc30f..b3aae8e5 100644 --- a/orm_lib/src/DbClientLockFree.cc +++ b/orm_lib/src/DbClientLockFree.cc @@ -46,11 +46,15 @@ DbClientLockFree::DbClientLockFree(const std::string &connInfo, trantor::EventLo LOG_TRACE << "type=" << (int)type; if (type == ClientType::PostgreSQL) { - newConnection(); + _loop->runInLoop([this](){ + _connectionHolder=newConnection(); + }); } else if (type == ClientType::Mysql) { - newConnection(); + _loop->runInLoop([this](){ + _connectionHolder=newConnection(); + }); } else { @@ -207,7 +211,7 @@ DbConnectionPtr DbClientLockFree::newConnection() auto thisPtr = weakPtr.lock(); if (!thisPtr) return; - thisPtr->newConnection(); + thisPtr->_connectionHolder=thisPtr->newConnection(); }); }); connPtr->setOkCallback([weakPtr](const DbConnectionPtr &okConnPtr) { diff --git a/orm_lib/src/DbClientLockFree.h b/orm_lib/src/DbClientLockFree.h index 3dbac3c6..ea5db7c9 100644 --- a/orm_lib/src/DbClientLockFree.h +++ b/orm_lib/src/DbClientLockFree.h @@ -60,6 +60,7 @@ class DbClientLockFree : public DbClient, public std::enable_shared_from_this