aboutsummaryrefslogtreecommitdiffstats
path: root/library/cpp
diff options
context:
space:
mode:
authorMaxim Yurchuk <maxim-yurchuk@ydb.tech>2025-05-30 21:14:52 +0000
committerGitHub <noreply@github.com>2025-05-30 21:14:52 +0000
commitc75cf6fa89ba44e2fa74a15232593b2e8423ed3f (patch)
treea7f428153ad7b3109180af04a9c84af2b0ab2a16 /library/cpp
parentb21606bc4b50665ea3fdca703e13a4b4d7a44284 (diff)
parent8728b9da66674488bde07a092040097e46de9366 (diff)
downloadydb-c75cf6fa89ba44e2fa74a15232593b2e8423ed3f.tar.gz
Library import 250529-1108 (#19003)
Diffstat (limited to 'library/cpp')
-rw-r--r--library/cpp/http/simple/http_client.cpp42
-rw-r--r--library/cpp/http/simple/http_client.h19
-rw-r--r--library/cpp/http/simple/http_client_options.h20
-rw-r--r--library/cpp/http/simple/ya.make1
-rw-r--r--library/cpp/int128/int128.h10
-rw-r--r--library/cpp/int128/ut/i128_find_ut.cpp16
-rw-r--r--library/cpp/int128/ut/ya.make1
-rw-r--r--library/cpp/neh/https.cpp7
-rw-r--r--library/cpp/openssl/crypto/rsa.cpp9
-rw-r--r--library/cpp/openssl/init/init.cpp65
-rw-r--r--library/cpp/openssl/init/ya.make2
-rw-r--r--library/cpp/openssl/io/stream.cpp9
-rw-r--r--library/cpp/tld/tlds-alpha-by-domain.txt3
-rw-r--r--library/cpp/unified_agent_client/logger.h11
-rw-r--r--library/cpp/uri/common.h4
15 files changed, 116 insertions, 103 deletions
diff --git a/library/cpp/http/simple/http_client.cpp b/library/cpp/http/simple/http_client.cpp
index 6fb04755391..87bbabc3f83 100644
--- a/library/cpp/http/simple/http_client.cpp
+++ b/library/cpp/http/simple/http_client.cpp
@@ -6,15 +6,25 @@
#include <util/string/cast.h>
#include <util/string/join.h>
#include <util/string/split.h>
+#include <util/system/spinlock.h>
+#include <library/cpp/cache/cache.h>
+
+
+TSpinLock TKeepAliveHttpClient::ConnectionQuarantineMutex;
+TQueue<THolder<NPrivate::THttpConnection>> TKeepAliveHttpClient::ConnectionQuarantine;
TKeepAliveHttpClient::TKeepAliveHttpClient(const TString& host,
ui32 port,
TDuration socketTimeout,
- TDuration connectTimeout)
+ TDuration connectTimeout,
+ bool useKeepAlive,
+ bool useConnectionPool)
: Host(CutHttpPrefix(host))
, Port(port)
, SocketTimeout(socketTimeout)
, ConnectTimeout(connectTimeout)
+ , UseKeepAlive(useKeepAlive)
+ , UseConnectionPool(useConnectionPool)
, IsHttps(host.StartsWith("https"))
, IsClosingRequired(false)
, HttpsVerification(TVerifyCert{Host})
@@ -159,13 +169,29 @@ bool TKeepAliveHttpClient::CreateNewConnectionIfNeeded() {
ConnectTimeout,
IsHttps,
ClientCertificate,
- HttpsVerification);
+ HttpsVerification,
+ UseKeepAlive);
IsClosingRequired = false;
return true;
}
return false;
}
+TKeepAliveHttpClient::~TKeepAliveHttpClient() {
+ if (UseConnectionPool) {
+ THolder<NPrivate::THttpConnection> oldConnection;
+ with_lock(ConnectionQuarantineMutex) {
+ while (ConnectionQuarantine.size() > 100) {
+ oldConnection = std::move(ConnectionQuarantine.front());
+
+ ConnectionQuarantine.pop();
+ oldConnection.Reset();
+ }
+ ConnectionQuarantine.push(std::move(Connection));
+ }
+ }
+}
+
THttpRequestException::THttpRequestException(int statusCode)
: StatusCode(statusCode)
{
@@ -180,6 +206,8 @@ TSimpleHttpClient::TSimpleHttpClient(const TOptions& options)
, Port(options.Port())
, SocketTimeout(options.SocketTimeout())
, ConnectTimeout(options.ConnectTimeout())
+ , UseKeepAlive(options.UseKeepAlive())
+ , UseConnectionPool(options.UseConnectionPool())
{
}
@@ -229,7 +257,8 @@ namespace NPrivate {
TDuration connTimeout,
bool isHttps,
const TMaybe<TOpenSslClientIO::TOptions::TClientCert>& clientCert,
- const TMaybe<TOpenSslClientIO::TOptions::TVerifyCert>& verifyCert)
+ const TMaybe<TOpenSslClientIO::TOptions::TVerifyCert>& verifyCert,
+ bool keepAlive)
: Addr(Resolve(host, port))
, Socket(Connect(Addr, sockTimeout, connTimeout, host, port))
, SocketIn(Socket)
@@ -249,8 +278,9 @@ namespace NPrivate {
} else {
HttpOut = MakeHolder<THttpOutput>(&SocketOut);
}
-
- HttpOut->EnableKeepAlive(true);
+ if (keepAlive) {
+ HttpOut->EnableKeepAlive(true);
+ }
}
TNetworkAddress THttpConnection::Resolve(const TString& host, ui32 port) {
@@ -292,7 +322,7 @@ TSimpleHttpClient::~TSimpleHttpClient() {
}
TKeepAliveHttpClient TSimpleHttpClient::CreateClient() const {
- TKeepAliveHttpClient cl(Host, Port, SocketTimeout, ConnectTimeout);
+ TKeepAliveHttpClient cl(Host, Port, SocketTimeout, ConnectTimeout, UseKeepAlive, UseConnectionPool);
if (!HttpsVerification) {
cl.DisableVerificationForHttps();
diff --git a/library/cpp/http/simple/http_client.h b/library/cpp/http/simple/http_client.h
index 3860862698d..87d3dc095af 100644
--- a/library/cpp/http/simple/http_client.h
+++ b/library/cpp/http/simple/http_client.h
@@ -8,6 +8,8 @@
#include <util/generic/strbuf.h>
#include <util/generic/yexception.h>
#include <util/network/socket.h>
+#include <util/generic/queue.h>
+#include <util/system/spinlock.h>
#include <library/cpp/http/io/stream.h>
#include <library/cpp/http/misc/httpcodes.h>
@@ -50,7 +52,12 @@ public:
TKeepAliveHttpClient(const TString& host,
ui32 port,
TDuration socketTimeout = TDuration::Seconds(5),
- TDuration connectTimeout = TDuration::Seconds(30));
+ TDuration connectTimeout = TDuration::Seconds(30),
+ bool useKeepAlive = true,
+ bool useConnectionPool = false);
+
+ TKeepAliveHttpClient(TKeepAliveHttpClient&&) = default;
+ ~TKeepAliveHttpClient();
THttpCode DoGet(const TStringBuf relativeUrl,
IOutputStream* output = nullptr,
@@ -117,8 +124,13 @@ private:
const ui32 Port;
const TDuration SocketTimeout;
const TDuration ConnectTimeout;
+ const bool UseKeepAlive;
+ const bool UseConnectionPool;
const bool IsHttps;
+ static TSpinLock ConnectionQuarantineMutex;
+ static TQueue<THolder<NPrivate::THttpConnection>> ConnectionQuarantine;
+
THolder<NPrivate::THttpConnection> Connection;
bool IsClosingRequired;
TMaybe<TClientCert> ClientCertificate;
@@ -158,6 +170,8 @@ protected:
const ui32 Port;
const TDuration SocketTimeout;
const TDuration ConnectTimeout;
+ const bool UseKeepAlive = true;
+ const bool UseConnectionPool = false;
bool HttpsVerification = false;
public:
@@ -215,7 +229,8 @@ namespace NPrivate {
TDuration connTimeout,
bool isHttps,
const TMaybe<TOpenSslClientIO::TOptions::TClientCert>& clientCert,
- const TMaybe<TOpenSslClientIO::TOptions::TVerifyCert>& verifyCert);
+ const TMaybe<TOpenSslClientIO::TOptions::TVerifyCert>& verifyCert,
+ bool keepAlive = true);
bool IsOk() const {
return IsNotSocketClosedByOtherSide(Socket);
diff --git a/library/cpp/http/simple/http_client_options.h b/library/cpp/http/simple/http_client_options.h
index 58849556a91..f237a3770a9 100644
--- a/library/cpp/http/simple/http_client_options.h
+++ b/library/cpp/http/simple/http_client_options.h
@@ -61,10 +61,30 @@ public:
return MaxRedirectCount_;
}
+ TSelf& UseKeepAlive(bool useKeepAlive) {
+ UseKeepAlive_ = useKeepAlive;
+ return *this;
+ }
+
+ bool UseKeepAlive() const noexcept {
+ return UseKeepAlive_;
+ }
+
+ TSelf& UseConnectionPool(bool useConnectionPool) {
+ UseConnectionPool_ = useConnectionPool;
+ return *this;
+ }
+
+ bool UseConnectionPool() const noexcept {
+ return UseConnectionPool_;
+ }
+
private:
TString Host_;
ui16 Port_;
TDuration SocketTimeout_ = TDuration::Seconds(5);
TDuration ConnectTimeout_ = TDuration::Seconds(30);
int MaxRedirectCount_ = INT_MAX;
+ bool UseKeepAlive_ = true;
+ bool UseConnectionPool_ = false;
};
diff --git a/library/cpp/http/simple/ya.make b/library/cpp/http/simple/ya.make
index 6a4e5775a4d..c645fb38442 100644
--- a/library/cpp/http/simple/ya.make
+++ b/library/cpp/http/simple/ya.make
@@ -1,6 +1,7 @@
LIBRARY()
PEERDIR(
+ library/cpp/cache
library/cpp/http/io
library/cpp/openssl/io
library/cpp/string_utils/url
diff --git a/library/cpp/int128/int128.h b/library/cpp/int128/int128.h
index 41f143e2959..47e24ff2b77 100644
--- a/library/cpp/int128/int128.h
+++ b/library/cpp/int128/int128.h
@@ -243,6 +243,8 @@ public:
return ret;
}
+ bool operator==(const TInteger128& a) const = default;
+
explicit constexpr operator bool() const noexcept {
return Low_ || High_;
}
@@ -478,14 +480,6 @@ namespace std {
};
}
-constexpr bool operator==(const ui128 lhs, const ui128 rhs) noexcept {
- return GetLow(lhs) == GetLow(rhs) && GetHigh(lhs) == GetHigh(rhs);
-}
-
-constexpr bool operator==(const i128 lhs, const i128 rhs) noexcept {
- return GetLow(lhs) == GetLow(rhs) && GetHigh(lhs) == GetHigh(rhs);
-}
-
constexpr bool operator!=(const ui128 lhs, const ui128 rhs) noexcept {
return !(lhs == rhs);
}
diff --git a/library/cpp/int128/ut/i128_find_ut.cpp b/library/cpp/int128/ut/i128_find_ut.cpp
new file mode 100644
index 00000000000..afc19b6dbae
--- /dev/null
+++ b/library/cpp/int128/ut/i128_find_ut.cpp
@@ -0,0 +1,16 @@
+#include <library/cpp/testing/unittest/registar.h>
+
+#include <library/cpp/int128/int128.h>
+
+#include <util/generic/cast.h>
+#include <util/generic/vector.h>
+
+#include <type_traits>
+
+Y_UNIT_TEST_SUITE(Int128FindSuite) {
+ Y_UNIT_TEST(Int128Find) {
+ const ui128 value = 10;
+ TVector<ui128> list = {1, 2, 3, 4, 5, 11, 10};
+ UNIT_ASSERT(Find(list, value) != list.end());
+ }
+}
diff --git a/library/cpp/int128/ut/ya.make b/library/cpp/int128/ut/ya.make
index 27b4b4dc884..2ee605429aa 100644
--- a/library/cpp/int128/ut/ya.make
+++ b/library/cpp/int128/ut/ya.make
@@ -12,6 +12,7 @@ SRCS(
i128_and_intrinsic_identity_ut.cpp
i128_comparison_ut.cpp
i128_division_ut.cpp
+ i128_find_ut.cpp
i128_type_traits_ut.cpp
ui128_division_ut.cpp
)
diff --git a/library/cpp/neh/https.cpp b/library/cpp/neh/https.cpp
index 99db8a44cc2..e14dcf86679 100644
--- a/library/cpp/neh/https.cpp
+++ b/library/cpp/neh/https.cpp
@@ -13,7 +13,6 @@
#include <openssl/err.h>
#include <openssl/x509v3.h>
-#include <library/cpp/openssl/init/init.h>
#include <library/cpp/openssl/method/io.h>
#include <library/cpp/coroutine/listener/listen.h>
#include <library/cpp/dns/cache.h>
@@ -358,12 +357,6 @@ namespace NNeh {
}
}
}
-
- struct TSSLInit {
- inline TSSLInit() {
- InitOpenSSL();
- }
- } SSL_INIT;
}
static inline void PrepareSocket(SOCKET s) {
diff --git a/library/cpp/openssl/crypto/rsa.cpp b/library/cpp/openssl/crypto/rsa.cpp
index 4b1d6648268..c9d2e07b89d 100644
--- a/library/cpp/openssl/crypto/rsa.cpp
+++ b/library/cpp/openssl/crypto/rsa.cpp
@@ -1,7 +1,6 @@
#include "rsa.h"
#include <library/cpp/openssl/big_integer/big_integer.h>
-#include <library/cpp/openssl/init/init.h>
#include <util/generic/yexception.h>
#include <util/generic/buffer.h>
@@ -12,14 +11,6 @@
using namespace NOpenSsl;
using namespace NOpenSsl::NRsa;
-namespace {
- struct TInit {
- inline TInit() {
- InitOpenSSL();
- }
- } INIT;
-}
-
TPublicKey::TPublicKey(const TBigInteger& e, const TBigInteger& n)
: Key_(RSA_new())
{
diff --git a/library/cpp/openssl/init/init.cpp b/library/cpp/openssl/init/init.cpp
index ae68ef08eaa..9a4e285ea35 100644
--- a/library/cpp/openssl/init/init.cpp
+++ b/library/cpp/openssl/init/init.cpp
@@ -1,66 +1,13 @@
-#include "init.h"
-
-#include <util/generic/singleton.h>
-#include <util/generic/vector.h>
-#include <util/generic/ptr.h>
-#include <util/generic/buffer.h>
-
-#include <util/system/yassert.h>
-#include <util/system/mutex.h>
-#include <util/system/thread.h>
-
-#include <util/random/entropy.h>
-#include <util/stream/input.h>
-
-#include <openssl/bio.h>
-#include <openssl/ssl.h>
-#include <openssl/err.h>
-#include <openssl/rand.h>
-#include <openssl/conf.h>
#include <openssl/crypto.h>
namespace {
- struct TInitSsl {
- struct TOpensslLocks {
- inline TOpensslLocks()
- : Mutexes(CRYPTO_num_locks())
- {
- for (auto& mpref : Mutexes) {
- mpref.Reset(new TMutex());
- }
- }
-
- inline void LockOP(int mode, int n) {
- auto& mutex = *Mutexes.at(n);
-
- if (mode & CRYPTO_LOCK) {
- mutex.Acquire();
- } else {
- mutex.Release();
- }
- }
-
- TVector<TAutoPtr<TMutex>> Mutexes;
- };
-
- inline TInitSsl() {
- OPENSSL_init_crypto(OPENSSL_INIT_NO_ATEXIT, nullptr);
- }
-
- inline ~TInitSsl() {
- OPENSSL_cleanup();
- }
-
- static void LockingFunction(int mode, int n, const char* /*file*/, int /*line*/) {
- Singleton<TOpensslLocks>()->LockOP(mode, n);
- }
-
- static unsigned long ThreadIdFunction() {
- return TThread::CurrentThreadId();
- }
- };
+ // Initialize OpenSSL as early as possible
+ // in order to prevent any further initializations with different flags.
+ //
+ // Initialize it with OPENSSL_INIT_NO_ATEXIT thus omitting the cleanup routine at process exit
+ // (it looks like it does nothing when openssl is linked statically).
+ [[maybe_unused]] auto _ = OPENSSL_init_crypto(OPENSSL_INIT_ENGINE_ALL_BUILTIN | OPENSSL_INIT_NO_ATEXIT, nullptr);
}
void InitOpenSSL() {
- (void)SingletonWithPriority<TInitSsl, 0>();
}
diff --git a/library/cpp/openssl/init/ya.make b/library/cpp/openssl/init/ya.make
index 1c39d273801..2d49965ca88 100644
--- a/library/cpp/openssl/init/ya.make
+++ b/library/cpp/openssl/init/ya.make
@@ -5,7 +5,7 @@ PEERDIR(
)
SRCS(
- init.cpp
+ GLOBAL init.cpp
)
END()
diff --git a/library/cpp/openssl/io/stream.cpp b/library/cpp/openssl/io/stream.cpp
index 0b4be38c0e3..2666988728f 100644
--- a/library/cpp/openssl/io/stream.cpp
+++ b/library/cpp/openssl/io/stream.cpp
@@ -4,7 +4,6 @@
#include <util/generic/singleton.h>
#include <util/generic/yexception.h>
-#include <library/cpp/openssl/init/init.h>
#include <library/cpp/openssl/method/io.h>
#include <library/cpp/resource/resource.h>
@@ -19,12 +18,6 @@ using TOptions = TOpenSslClientIO::TOptions;
namespace {
struct TSslIO;
- struct TSslInitOnDemand {
- inline TSslInitOnDemand() {
- InitOpenSSL();
- }
- };
-
int GetLastSslError() noexcept {
return ERR_peek_last_error();
}
@@ -121,7 +114,7 @@ namespace {
IOutputStream* Out;
};
- struct TSslIO: public TSslInitOnDemand, public TOptions {
+ struct TSslIO: public TOptions {
inline TSslIO(IInputStream* in, IOutputStream* out, const TOptions& opts)
: TOptions(opts)
, Io(in, out)
diff --git a/library/cpp/tld/tlds-alpha-by-domain.txt b/library/cpp/tld/tlds-alpha-by-domain.txt
index 040f4f01ac7..fc8f36a83ec 100644
--- a/library/cpp/tld/tlds-alpha-by-domain.txt
+++ b/library/cpp/tld/tlds-alpha-by-domain.txt
@@ -1,4 +1,4 @@
-# Version 2025051600, Last Updated Fri May 16 07:07:02 2025 UTC
+# Version 2025052800, Last Updated Wed May 28 07:07:02 2025 UTC
AAA
AARP
ABB
@@ -912,7 +912,6 @@ POLITIE
PORN
POST
PR
-PRAMERICA
PRAXI
PRESS
PRIME
diff --git a/library/cpp/unified_agent_client/logger.h b/library/cpp/unified_agent_client/logger.h
index 8130c2894c3..01c3e0ed747 100644
--- a/library/cpp/unified_agent_client/logger.h
+++ b/library/cpp/unified_agent_client/logger.h
@@ -35,6 +35,17 @@
YLOG(TLOG_CRIT, msg, Logger); \
_Exit(1);
+#define YLOG_EMERG_F(fmt, ...) YLOG_EMERG(std::format(fmt, __VA_ARGS__))
+#define YLOG_ALERT_F(fmt, ...) YLOG_ALERT(std::format(fmt, __VA_ARGS__))
+#define YLOG_CRIT_F(fmt, ...) YLOG_CRIT(std::format(fmt, __VA_ARGS__))
+#define YLOG_ERR_F(fmt, ...) YLOG_ERR(std::format(fmt, __VA_ARGS__))
+#define YLOG_WARNING_F(fmt, ...) YLOG_WARNING(std::format(fmt, __VA_ARGS__))
+#define YLOG_NOTICE_F(fmt, ...) YLOG_NOTICE(std::format(fmt, __VA_ARGS__))
+#define YLOG_INFO_F(fmt, ...) YLOG_INFO(std::format(fmt, __VA_ARGS__))
+#define YLOG_DEBUG_F(fmt, ...) YLOG_DEBUG(std::format(fmt, __VA_ARGS__))
+#define YLOG_RESOURCES_F(fmt, ...) YLOG_RESOURCES(std::format(fmt, __VA_ARGS__))
+#define YLOG_FATAL_F(fmt, ...) YLOG_FATAL(std::format(fmt, __VA_ARGS__))
+
namespace NUnifiedAgent {
class TScopeLogger;
diff --git a/library/cpp/uri/common.h b/library/cpp/uri/common.h
index 23be2571fc5..7945340f089 100644
--- a/library/cpp/uri/common.h
+++ b/library/cpp/uri/common.h
@@ -366,7 +366,9 @@ namespace NUri {
NewFeaturesRecommended = 0 | FeatureSchemeKnown | FeatureRemoteOnly | FeatureToLower | FeatureCheckHost | FeatureConvertHostIDN | FeatureFragmentToHashBang | FeatureEncodeSpace | FeatureEncodeCntrl | FeatureEncodeExtendedASCII | FeatureUpperEncoded | FeatureDecodeUnreserved | FeaturePathOperation | FeaturePathStripRootParent,
// FeaturesRobot is deprecated, use NewFeaturesRecommended: ROBOTQUALITY-718
- FeaturesRobot = FeaturesRecommended
+ FeaturesRobot = FeaturesRecommended,
+
+ FeaturesDefaultOrSchemeKnown = 0 | FeaturesDefault | FeatureSchemeKnown
};
};