Skip to content

Commit fe0c4d0

Browse files
committed
Fix crash in connection tree
Fix RedisInsight#4039
1 parent a7ad1f8 commit fe0c4d0

File tree

1 file changed

+16
-26
lines changed

1 file changed

+16
-26
lines changed

src/app/models/treeoperations.cpp

Lines changed: 16 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -21,40 +21,30 @@ TreeOperations::TreeOperations(
2121

2222
bool TreeOperations::loadDatabases(
2323
std::function<void(RedisClient::DatabaseList)> callback) {
24-
bool connected = m_connection->isConnected();
25-
26-
if (connected) {
27-
try {
28-
m_connection->refreshServerInfo();
29-
} catch (const RedisClient::Connection::Exception& e) {
30-
emit m_events->error(
31-
QCoreApplication::translate("RDM", "Connection error: ") +
32-
QString(e.what()));
33-
return false;
34-
}
35-
} else {
36-
try {
37-
connected = m_connection->connect(true);
38-
} catch (const RedisClient::Connection::Exception& e) {
39-
emit m_events->error(
40-
QCoreApplication::translate("RDM", "Connection error: ") +
41-
QString(e.what()));
42-
return false;
43-
}
24+
auto connection = m_connection->clone();
25+
26+
bool connected = false;
27+
28+
try {
29+
connected = connection->connect(true);
30+
} catch (const RedisClient::Connection::Exception& e) {
31+
emit m_events->error(
32+
QCoreApplication::translate("RDM", "Connection error: ") +
33+
QString(e.what()));
34+
return false;
4435
}
4536

4637
if (!connected) {
4738
emit m_events->error(
4839
QCoreApplication::translate(
4940
"RDM", "Cannot connect to server '%1'. Check log for details.")
50-
.arg(m_connection->getConfig().name()));
41+
.arg(connection->getConfig().name()));
5142
return false;
5243
}
5344

54-
RedisClient::DatabaseList availableDatabeses =
55-
m_connection->getKeyspaceInfo();
45+
RedisClient::DatabaseList availableDatabeses = connection->getKeyspaceInfo();
5646

57-
if (m_connection->mode() != RedisClient::Connection::Mode::Cluster) {
47+
if (connection->mode() != RedisClient::Connection::Mode::Cluster) {
5848
// detect all databases
5949
RedisClient::Response scanningResp;
6050
int lastDbIndex =
@@ -65,13 +55,13 @@ bool TreeOperations::loadDatabases(
6555
availableDatabeses.insert(index, 0);
6656
}
6757
} else {
68-
uint dbScanLimit = static_cast<ServerConfig>(m_connection->getConfig())
58+
uint dbScanLimit = static_cast<ServerConfig>(connection->getConfig())
6959
.databaseScanLimit();
7060

7161
for (int index = lastDbIndex; index < dbScanLimit; index++) {
7262
try {
7363
scanningResp =
74-
m_connection->commandSync("select", QString::number(index));
64+
connection->commandSync("select", QString::number(index));
7565
} catch (const RedisClient::Connection::Exception& e) {
7666
throw ConnectionsTree::Operations::Exception(
7767
QCoreApplication::translate("RDM", "Connection error: ") +

0 commit comments

Comments
 (0)