Skip to content

Commit d6a33f9

Browse files
authored
Added handleFatalError in handleClosed (#2291)
1 parent 59cd436 commit d6a33f9

File tree

2 files changed

+15
-3
lines changed

2 files changed

+15
-3
lines changed

orm_lib/src/DbConnection.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ class DbConnection : public trantor::NonCopyable
118118

119119
virtual ~DbConnection()
120120
{
121-
LOG_TRACE << "Destruct DbConn" << this;
121+
LOG_TRACE << "Destruct DbConn " << this;
122122
}
123123

124124
ConnectStatus status() const

orm_lib/src/postgresql_impl/PgConnection.cc

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,15 @@ void PgConnection::handleClosed()
133133
if (status_ == ConnectStatus::Bad)
134134
return;
135135
status_ = ConnectStatus::Bad;
136+
137+
if (isWorking_)
138+
{
139+
// Connection was closed unexpectedly while isWorking_ was true.
140+
isWorking_ = false;
141+
handleFatalError();
142+
callback_ = nullptr;
143+
}
144+
136145
channel_.disableAll();
137146
channel_.remove();
138147
assert(closeCallback_);
@@ -406,10 +415,13 @@ void PgConnection::doAfterPreparing()
406415

407416
void PgConnection::handleFatalError()
408417
{
409-
auto exceptPtr =
410-
std::make_exception_ptr(Failure(PQerrorMessage(connectionPtr_.get())));
411418
if (exceptionCallback_)
419+
{
420+
auto exceptPtr = std::make_exception_ptr(
421+
Failure(PQerrorMessage(connectionPtr_.get())));
412422
exceptionCallback_(exceptPtr);
423+
}
424+
413425
exceptionCallback_ = nullptr;
414426
}
415427

0 commit comments

Comments
 (0)