From 6844c65d8415d8e287189694d4fa6a32625db97b Mon Sep 17 00:00:00 2001 From: Alex Fabijanic Date: Fri, 9 Feb 2018 08:57:37 -0600 Subject: [PATCH] POCO SQLite Data Connector hangs #2108 --- SQL/SQLite/src/SessionImpl.cpp | 51 ++++++++++------------------------ gradle | 2 +- openssl | 2 +- 3 files changed, 16 insertions(+), 39 deletions(-) diff --git a/SQL/SQLite/src/SessionImpl.cpp b/SQL/SQLite/src/SessionImpl.cpp index 5f92e029c..509def7cf 100644 --- a/SQL/SQLite/src/SessionImpl.cpp +++ b/SQL/SQLite/src/SessionImpl.cpp @@ -17,8 +17,7 @@ #include "Poco/SQL/SQLite/SQLiteStatementImpl.h" #include "Poco/SQL/SQLite/SQLiteException.h" #include "Poco/SQL/Session.h" -#include "Poco/ActiveMethod.h" -#include "Poco/ActiveResult.h" +#include "Poco/Stopwatch.h" #include "Poco/String.h" #include "Poco/Mutex.h" #include "Poco/SQL/SQLException.h" @@ -140,32 +139,6 @@ bool SessionImpl::isTransactionIsolation(Poco::UInt32 ti) const } -class ActiveConnector -{ -public: - ActiveConnector(const std::string& connectString, sqlite3** ppDB): - connect(this, &ActiveConnector::connectImpl), - _connectString(connectString), - _ppDB(ppDB) - { - poco_check_ptr(_ppDB); - } - - ActiveMethod connect; - -private: - ActiveConnector(); - - inline int connectImpl() - { - return sqlite3_open_v2(_connectString.c_str(), _ppDB, SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE | SQLITE_OPEN_URI, NULL); - } - - std::string _connectString; - sqlite3** _ppDB; -}; - - void SessionImpl::open(const std::string& connect) { if (connect != connectionString()) @@ -181,16 +154,20 @@ void SessionImpl::open(const std::string& connect) try { - ActiveConnector connector(connectionString(), &_pDB); - ActiveResult result = connector.connect(); - if (!result.tryWait(static_cast(getLoginTimeout() * 1000))) - throw ConnectionFailedException("Timed out."); - - int rc = result.data(); - if (rc != 0) + int rc = 0; + size_t tout = getLoginTimeout(); + Stopwatch sw; sw.start(); + while (true) { - close(); - Utility::throwException(_pDB, rc); + rc = sqlite3_open_v2(connectionString().c_str(), &_pDB, + SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE | SQLITE_OPEN_URI, NULL); + if (rc == SQLITE_OK) break; + if (sw.elapsedSeconds() >= tout) + { + close(); + Utility::throwException(_pDB, rc); + } + else Thread::sleep(10); } } catch (SQLiteException& ex) diff --git a/gradle b/gradle index 05a8d4d93..73b60316d 160000 --- a/gradle +++ b/gradle @@ -1 +1 @@ -Subproject commit 05a8d4d93581b2e780bad84f8f9178b8a4267eda +Subproject commit 73b60316d69e239902711f32dca95f6d97aa257c diff --git a/openssl b/openssl index 26b1673ca..b42dcf217 160000 --- a/openssl +++ b/openssl @@ -1 +1 @@ -Subproject commit 26b1673caad94a702b6d694f48f917a283b30777 +Subproject commit b42dcf2175f30e0c21dc9a684f0b9670f4ed09c8