Maaz2212 opened a new pull request, #13957:
URL: https://github.com/apache/trafficserver/pull/13957
<!--
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.
-->
## Description
Every incoming client TCP connection currently acquires two locks in
`ConnectionTracker` on accept and one on close, regardless of configuration:
1. `client_exempt_list_mutex` (shared lock) in
`ConnectionTracker::is_client_exempt()`, taken even when
`proxy.config.http.per_client.connection.exempt_list` is empty.
2. `_inbound_table._mutex` (exclusive lock) in
`ConnectionTracker::obtain_inbound()`, which finds or creates a `Group` for the
client IP and inserts it into `_inbound_table`. When the connection closes,
`Group::release()` acquires the same mutex again to erase the `Group`.
The inbound table lock was taken because
`NetHandler::get_per_client_max_connections_in()` mapped `0` (the default "no
limit" setting) to `INT32_MAX - 1`, causing `client_max > 0` in
`handle_max_client_connections()` to always evaluate to `true`.
### Changes
- `src/iocore/net/NetHandler.cc`: Return `0` from
`NetHandler::get_per_client_max_connections_in()` when disabled instead of
`INT32_MAX - 1`. When `proxy.config.net.per_client.max_connections_in` is `0`,
connection tracking is bypassed entirely, avoiding table locking and heap
allocations on every accept and close.
- `include/iocore/net/ConnectionTracker.h`,
`src/iocore/net/ConnectionTracker.cc`: Added an atomic flag
`has_client_exempt_entries` to `GlobalConfig`. Readers in `is_client_exempt()`
check this flag and return `false` immediately without acquiring
`client_exempt_list_mutex` when no exempt list is configured.
- `src/iocore/net/unit_tests/test_ConnectionTracker.cc`: Added Catch2 unit
tests verifying exempt list behavior, range additions/removals, and list
clearing.
Fixes: #13890
## Testing Done
- **Code Formatting**: Verified with `cmake --build build-dev -t format` in
CI container (`ci.trafficserver.apache.org/ats/fedora:44`).
- **Unit Tests**: Built and executed `test_net` (`[ConnectionTracker]`),
passing all 3 test cases / 97 assertions; full `test_net` suite passed (2815
assertions in 77 test cases).
- **Uranium Tests**: Ran `./tests/urtest.sh -q -k "per_client_connection_max
or connections_throttle"`, passing all 15 scenarios.
--
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]