Skip to content

Commit

Permalink
Merge pull request #51046 from ClickHouse/backport/23.3/50334
Browse files Browse the repository at this point in the history
Backport #50334 to 23.3: Fix crash when Pool::Entry::disconnect() is called
  • Loading branch information
alexey-milovidov committed Jun 16, 2023
2 parents 823ac8e + 19a74d0 commit 2c99b73
Showing 1 changed file with 3 additions and 10 deletions.
13 changes: 3 additions & 10 deletions src/Common/mysqlxx/Pool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,10 @@ void Pool::Entry::decrementRefCount()
{
/// We were the last user of this thread, deinitialize it
mysql_thread_end();
}
else if (data->removed_from_pool)
{
/// data->ref_count == 0 in case we removed connection from pool (see Pool::removeConnection).
chassert(ref_count == 0);
/// In Pool::Entry::disconnect() we remove connection from the list of pool's connections.
/// So now we must deallocate the memory.
::delete data;
if (data->removed_from_pool)
::delete data;
}
}

Expand Down Expand Up @@ -234,11 +230,8 @@ void Pool::removeConnection(Connection* connection)
std::lock_guard lock(mutex);
if (connection)
{
if (connection->ref_count > 0)
{
if (!connection->removed_from_pool)
connection->conn.disconnect();
connection->ref_count = 0;
}
connections.remove(connection);
connection->removed_from_pool = true;
}
Expand Down

0 comments on commit 2c99b73

Please sign in to comment.