From 66e6980413da916e73bf16e3649a210cb81a57c6 Mon Sep 17 00:00:00 2001 From: jianfengmao Date: Wed, 21 Jan 2026 14:36:33 -0700 Subject: [PATCH 1/3] Fix cookie duplication bug --- cpp/src/arrow/flight/cookie_internal.cc | 6 ++++++ cpp/src/arrow/flight/cookie_internal.h | 8 +++++++- .../flight/sql/odbc/odbc_impl/flight_sql_connection.cc | 3 --- 3 files changed, 13 insertions(+), 4 deletions(-) diff --git a/cpp/src/arrow/flight/cookie_internal.cc b/cpp/src/arrow/flight/cookie_internal.cc index 99fa8b238ddc..694a9a3e71a7 100644 --- a/cpp/src/arrow/flight/cookie_internal.cc +++ b/cpp/src/arrow/flight/cookie_internal.cc @@ -64,6 +64,12 @@ size_t CaseInsensitiveHash::operator()(const std::string& key) const { return std::hash{}(upper_string); } +bool CaseInsensitiveEqual::operator()(std::string_view lhs, + std::string_view rhs) const { + if (lhs.size() != rhs.size()) return false; + return strcasecmp(std::string(lhs).c_str(), std::string(rhs).c_str()) == 0; +} + Cookie Cookie::Parse(std::string_view cookie_header_value) { // Parse the cookie string. If the cookie has an expiration, record it. // If the cookie has a max-age, calculate the current time + max_age and set that as diff --git a/cpp/src/arrow/flight/cookie_internal.h b/cpp/src/arrow/flight/cookie_internal.h index 62c0390c585b..98b936edb338 100644 --- a/cpp/src/arrow/flight/cookie_internal.h +++ b/cpp/src/arrow/flight/cookie_internal.h @@ -41,6 +41,12 @@ class ARROW_FLIGHT_EXPORT CaseInsensitiveComparator { bool operator()(const std::string& t1, const std::string& t2) const; }; +/// \brief Case insensitive equality comparator for use by unordered cookie map. +class ARROW_FLIGHT_EXPORT CaseInsensitiveEqual { + public: + bool operator()(const std::string& lhs, const std::string& rhs) const; +}; + /// \brief Case insensitive hasher for use by cookie caching map. Cookies are not /// case-sensitive. class ARROW_FLIGHT_EXPORT CaseInsensitiveHash { @@ -117,7 +123,7 @@ class ARROW_FLIGHT_EXPORT CookieCache { // Mutex must be used to protect cookie cache. std::mutex mutex_; - std::unordered_map + std::unordered_map cookies; }; diff --git a/cpp/src/arrow/flight/sql/odbc/odbc_impl/flight_sql_connection.cc b/cpp/src/arrow/flight/sql/odbc/odbc_impl/flight_sql_connection.cc index 6c9f5a5ed19e..abe82b36c454 100644 --- a/cpp/src/arrow/flight/sql/odbc/odbc_impl/flight_sql_connection.cc +++ b/cpp/src/arrow/flight/sql/odbc/odbc_impl/flight_sql_connection.cc @@ -158,9 +158,6 @@ void FlightSqlConnection::Connect(const ConnPropertyMap& properties, client_options_ = BuildFlightClientOptions(properties, missing_attr, flight_ssl_configs); - const std::shared_ptr& cookie_factory = GetCookieFactory(); - client_options_.middleware.push_back(cookie_factory); - std::unique_ptr flight_client; ThrowIfNotOK(FlightClient::Connect(location, client_options_).Value(&flight_client)); PopulateMetadataSettings(properties); From c9cdaeeffda78722bb3f0d9e63f273dc61a7da28 Mon Sep 17 00:00:00 2001 From: jianfengmao Date: Thu, 22 Jan 2026 12:49:24 -0700 Subject: [PATCH 2/3] Fix a compilation error --- cpp/src/arrow/flight/cookie_internal.cc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cpp/src/arrow/flight/cookie_internal.cc b/cpp/src/arrow/flight/cookie_internal.cc index 694a9a3e71a7..6c9b31522340 100644 --- a/cpp/src/arrow/flight/cookie_internal.cc +++ b/cpp/src/arrow/flight/cookie_internal.cc @@ -64,8 +64,8 @@ size_t CaseInsensitiveHash::operator()(const std::string& key) const { return std::hash{}(upper_string); } -bool CaseInsensitiveEqual::operator()(std::string_view lhs, - std::string_view rhs) const { +bool CaseInsensitiveEqual::operator()(std::string& lhs, + std::string& rhs) const { if (lhs.size() != rhs.size()) return false; return strcasecmp(std::string(lhs).c_str(), std::string(rhs).c_str()) == 0; } From 5ca5cffdbf3c50a9ef0f5833aa2f1cdfc14bb6a2 Mon Sep 17 00:00:00 2001 From: jianfengmao Date: Thu, 22 Jan 2026 13:13:20 -0700 Subject: [PATCH 3/3] Correct the signature of CaseInsensitiveEqual --- cpp/src/arrow/flight/cookie_internal.cc | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/cpp/src/arrow/flight/cookie_internal.cc b/cpp/src/arrow/flight/cookie_internal.cc index 6c9b31522340..df09a77afb72 100644 --- a/cpp/src/arrow/flight/cookie_internal.cc +++ b/cpp/src/arrow/flight/cookie_internal.cc @@ -64,10 +64,9 @@ size_t CaseInsensitiveHash::operator()(const std::string& key) const { return std::hash{}(upper_string); } -bool CaseInsensitiveEqual::operator()(std::string& lhs, - std::string& rhs) const { - if (lhs.size() != rhs.size()) return false; - return strcasecmp(std::string(lhs).c_str(), std::string(rhs).c_str()) == 0; +bool CaseInsensitiveEqual::operator()(const std::string& lhs, + const std::string& rhs) const { + return strcasecmp(lhs.c_str(), rhs.c_str()) == 0; } Cookie Cookie::Parse(std::string_view cookie_header_value) {