Copilot commented on code in PR #13579:
URL: https://github.com/apache/trafficserver/pull/13579#discussion_r3829983127
##########
include/proxy/http/HttpSessionManager.h:
##########
@@ -85,14 +85,33 @@ class ServerSessionPool : public Continuation
static bool match(PoolableSession *ss, sockaddr const *addr, CryptoHash
const &host_hash,
TSServerSessionSharingMatchMask match_style);
- /** Get a session from the pool.
-
- The session is selected based on @a match_style equivalently to @a
match. If found the session
- is removed from the pool.
-
- @return A pointer to the session or @c NULL if not matching session was
found.
- */
- HSMresult_t acquireSession(sockaddr const *addr, CryptoHash const
&host_hash, TSServerSessionSharingMatchMask match_style,
+ /** Search the pool for a server session compatible with the given address,
hostname, and state machine.
+ *
+ * The selection criteria are controlled by @p match_style. At least one of
+ * @c TS_SERVER_SESSION_SHARING_MATCH_MASK_IP or @c
TS_SERVER_SESSION_SHARING_MATCH_MASK_HOSTONLY
+ * must be set for a match to be possible; if neither is set, @c
HSMresult_t::NOT_FOUND is
+ * returned unconditionally.
+ *
+ * When a compatible session is found and does not support multiplexed
streams, it is removed from
+ * the pool and ownership transfers to the caller. A session that supports
multiplexed streams is
+ * not removed and remains available for subsequent acquisitions.
+ *
+ * @param[in] addr Remote address and port to match.
+ * @param[in] hostname_hash Cryptographic hash of the target hostname.
+ * @param[in] match_style Bitmask of @c TSServerSessionSharingMatchMask
values specifying which
+ * attributes must agree between the candidate
session and the request.
+ * @param[in] sm The requesting HTTP state machine; consulted
for SNI and certificate
+ * validation when the corresponding bits are set
in @p match_style.
Review Comment:
The updated `acquireSession()` docs imply `sm` is only used when SNI/cert
bits are set in `match_style`, but the implementation also consults `sm` for
origin certificate hostname validation when the candidate session is
multiplexing (see `validate_session_origin_cert()` in `HttpSessionManager.cc`).
This matters because callers (and the new unit tests) may pass `sm == nullptr`
under some match styles.
##########
src/proxy/http/unit_tests/test_HttpSessionManager.cc:
##########
@@ -0,0 +1,333 @@
+/** @file
+
+ Unit tests for ServerSessionPool::acquireSession.
+
+ @section license License
+
+ Licensed to the Apache Software Foundation (ASF) under one
+ or more contributor license agreements. See the NOTICE file
+ distributed with this work for additional information
+ regarding copyright ownership. The ASF licenses this file
+ to you under the Apache License, Version 2.0 (the
+ "License"); you may not use this file except in compliance
+ with the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+ */
+
+#include "proxy/http/HttpSessionManager.h"
+#include "proxy/http/HttpConfig.h"
+
+#include <catch2/catch_test_macros.hpp>
+
+#include <memory>
+#include <vector>
+
+namespace
+{
+
+/** A minimal PoolableSession that can be pooled and matched.
+ *
+ * Only the remote address and the hostname hash participate in the match
+ * paths exercised here, so no NetVConnection is required. The session must
+ * not be multiplexing, otherwise acquireSession consults the HttpSM.
+ */
+class TestPoolableSession : public PoolableSession
+{
+public:
+ TestPoolableSession(char const *addr_str, char const *hostname)
+ {
+ ink_release_assert(ats_ip_pton(addr_str, &_remote_addr) == 0);
+ this->attach_hostname(hostname);
+ }
+
+ void
+ new_connection(NetVConnection *, MIOBuffer *, IOBufferReader *) override
+ {
+ }
+ void
+ start() override
+ {
+ }
+ void
+ release(ProxyTransaction *) override
+ {
+ }
+ void
+ destroy() override
+ {
+ }
+ void
+ free() override
+ {
+ }
+ void
+ increment_current_active_connections_stat() override
+ {
+ }
+ void
+ decrement_current_active_connections_stat() override
+ {
+ }
+
+ int
+ get_transact_count() const override
+ {
+ return 0;
+ }
+
+ const char *
+ get_protocol_string() const override
+ {
+ return "test";
+ }
+
+ IOBufferReader *
+ get_remote_reader() override
+ {
+ return nullptr;
+ }
+
+ void
+ do_io_close(int /* lerrno ATS_UNUSED */ = -1) override
+ {
+ ++close_count;
+ }
+
+ sockaddr const *
+ get_remote_addr() const override
+ {
+ return &_remote_addr.sa;
+ }
+
+ int close_count = 0;
+
+private:
+ IpEndpoint _remote_addr;
+};
+
+/// Owns the test sessions and hands raw pointers to the pool under test.
+class SessionFactory
+{
+public:
+ TestPoolableSession *
+ make(char const *addr_str, char const *hostname)
+ {
+ return
_sessions.emplace_back(std::make_unique<TestPoolableSession>(addr_str,
hostname)).get();
+ }
+
+private:
+ std::vector<std::unique_ptr<TestPoolableSession>> _sessions;
+};
+
+/// The pool bookkeeping updates this gauge, which the test binary never
registers.
+void
+init_metrics()
+{
+ if (http_rsb.pooled_server_connections == nullptr) {
+ http_rsb.pooled_server_connections =
Metrics::Gauge::createPtr("proxy.process.http.pooled_server_connections");
+ }
+}
Review Comment:
`ServerSessionPool::addSession()` / `removeSession()` update
`http_rsb.pooled_server_connections`, but this test never restores that global
gauge back to 0. Because `pool.purge()` does not decrement the gauge, the
metric value will accumulate across Catch2 section runs, making the unit test
process stateful and potentially order-dependent for other tests.
##########
src/proxy/http/unit_tests/test_HttpSessionManager.cc:
##########
@@ -0,0 +1,333 @@
+/** @file
+
+ Unit tests for ServerSessionPool::acquireSession.
+
+ @section license License
+
+ Licensed to the Apache Software Foundation (ASF) under one
+ or more contributor license agreements. See the NOTICE file
+ distributed with this work for additional information
+ regarding copyright ownership. The ASF licenses this file
+ to you under the Apache License, Version 2.0 (the
+ "License"); you may not use this file except in compliance
+ with the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+ */
+
+#include "proxy/http/HttpSessionManager.h"
+#include "proxy/http/HttpConfig.h"
+
+#include <catch2/catch_test_macros.hpp>
+
+#include <memory>
+#include <vector>
+
Review Comment:
This file calls `strlen()` in `hash_of()` (line 143) but does not include
`<cstring>`, and it uses the unqualified C function rather than `std::strlen`.
Other unit tests in this directory include `<cstring>` and use `std::strlen`
(e.g. `test_ForwardedConfig.cc`, `test_ChunkedHandler.cc`). This can make the
compilation depend on transitive includes.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]