diff --git a/orm_lib/src/DbConnection.h b/orm_lib/src/DbConnection.h index c49838a2a0..35e27e72dc 100644 --- a/orm_lib/src/DbConnection.h +++ b/orm_lib/src/DbConnection.h @@ -118,7 +118,7 @@ class DbConnection : public trantor::NonCopyable virtual ~DbConnection() { - LOG_TRACE << "Destruct DbConn" << this; + LOG_TRACE << "Destruct DbConn " << this; } ConnectStatus status() const diff --git a/orm_lib/src/postgresql_impl/PgConnection.cc b/orm_lib/src/postgresql_impl/PgConnection.cc index a318a81787..8687159d7c 100644 --- a/orm_lib/src/postgresql_impl/PgConnection.cc +++ b/orm_lib/src/postgresql_impl/PgConnection.cc @@ -133,6 +133,15 @@ void PgConnection::handleClosed() if (status_ == ConnectStatus::Bad) return; status_ = ConnectStatus::Bad; + + if (isWorking_) + { + // Connection was closed unexpectedly while isWorking_ was true. + isWorking_ = false; + handleFatalError(); + callback_ = nullptr; + } + channel_.disableAll(); channel_.remove(); assert(closeCallback_); @@ -406,10 +415,13 @@ void PgConnection::doAfterPreparing() void PgConnection::handleFatalError() { - auto exceptPtr = - std::make_exception_ptr(Failure(PQerrorMessage(connectionPtr_.get()))); if (exceptionCallback_) + { + auto exceptPtr = std::make_exception_ptr( + Failure(PQerrorMessage(connectionPtr_.get()))); exceptionCallback_(exceptPtr); + } + exceptionCallback_ = nullptr; }