From dedc25fd341abacd6c9d8719aabb8feb1e824518 Mon Sep 17 00:00:00 2001 From: Alexander Tokmakov Date: Tue, 9 Apr 2024 23:43:40 +0200 Subject: [PATCH] fix --- src/Client/Connection.cpp | 16 ++++++++++------ src/Client/Connection.h | 3 ++- src/Client/IServerConnection.h | 2 +- src/Client/LocalConnection.h | 2 +- 4 files changed, 14 insertions(+), 9 deletions(-) diff --git a/src/Client/Connection.cpp b/src/Client/Connection.cpp index e5ac7ad66b9..f791a77a261 100644 --- a/src/Client/Connection.cpp +++ b/src/Client/Connection.cpp @@ -214,7 +214,7 @@ void Connection::connect(const ConnectionTimeouts & timeouts) DNSResolver::instance().removeHostFromCache(host); /// Add server address to exception. Exception will preserve stack trace. - e.addMessage("({})", getDescription()); + e.addMessage("({})", getDescription(/*with_extra*/ true)); throw; } catch (Poco::Net::NetException & e) @@ -225,7 +225,7 @@ void Connection::connect(const ConnectionTimeouts & timeouts) DNSResolver::instance().removeHostFromCache(host); /// Add server address to exception. Also Exception will remember new stack trace. It's a pity that more precise exception type is lost. - throw NetException(ErrorCodes::NETWORK_ERROR, "{} ({})", e.displayText(), getDescription()); + throw NetException(ErrorCodes::NETWORK_ERROR, "{} ({})", e.displayText(), getDescription(/*with_extra*/ true)); } catch (Poco::TimeoutException & e) { @@ -241,7 +241,7 @@ void Connection::connect(const ConnectionTimeouts & timeouts) ErrorCodes::SOCKET_TIMEOUT, "{} ({}, connection timeout {} ms)", e.displayText(), - getDescription(), + getDescription(/*with_extra*/ true), connection_timeout.totalMilliseconds()); } } @@ -473,8 +473,10 @@ const String & Connection::getDefaultDatabase() const return default_database; } -const String & Connection::getDescription() const +const String & Connection::getDescription(bool with_extra) const { + if (with_extra) + return full_description; return description; } @@ -1227,10 +1229,12 @@ void Connection::setDescription() description += ", " + ip_address; } + full_description = description; + if (const auto * socket_ = getSocket()) { - description += ", local address: "; - description += socket_->address().toString(); + full_description += ", local address: "; + full_description += socket_->address().toString(); } } diff --git a/src/Client/Connection.h b/src/Client/Connection.h index 5d0411027a1..20c66caa744 100644 --- a/src/Client/Connection.h +++ b/src/Client/Connection.h @@ -89,7 +89,7 @@ public: const String & getServerDisplayName(const ConnectionTimeouts & timeouts) override; /// For log and exception messages. - const String & getDescription() const override; + const String & getDescription(bool with_extra = false) const override; const String & getHost() const; UInt16 getPort() const; const String & getDefaultDatabase() const; @@ -187,6 +187,7 @@ private: /// For messages in log and in exceptions. String description; + String full_description; void setDescription(); /// Returns resolved address if it was resolved. diff --git a/src/Client/IServerConnection.h b/src/Client/IServerConnection.h index a0c029c79fb..724afa95d7a 100644 --- a/src/Client/IServerConnection.h +++ b/src/Client/IServerConnection.h @@ -88,7 +88,7 @@ public: virtual const String & getServerTimezone(const ConnectionTimeouts & timeouts) = 0; virtual const String & getServerDisplayName(const ConnectionTimeouts & timeouts) = 0; - virtual const String & getDescription() const = 0; + virtual const String & getDescription(bool with_extra = false) const = 0; virtual std::vector> getPasswordComplexityRules() const = 0; diff --git a/src/Client/LocalConnection.h b/src/Client/LocalConnection.h index 9c2d0a81d8d..6218fbe341f 100644 --- a/src/Client/LocalConnection.h +++ b/src/Client/LocalConnection.h @@ -90,7 +90,7 @@ public: const String & getServerTimezone(const ConnectionTimeouts & timeouts) override; const String & getServerDisplayName(const ConnectionTimeouts & timeouts) override; - const String & getDescription() const override { return description; } + const String & getDescription([[maybe_unused]] bool with_extra = false) const override { return description; } std::vector> getPasswordComplexityRules() const override { return {}; }