[USM] Fix ssl_sock_by_ctx leak
What does this PR do?
Adds logic to handle connection closures without SSL_shutdown, relying solely on tcp_close. The solution involves creating a new map, ssl_ctx_by_tuple, to clean up the connection using the connection tuple (conn_tup).
Motivation
The ssl_sock_by_ctx is leaking due to SSL connections being closed only via TCP close without calling SSL_SHUTDOWN.
This PR adds the ability to remove the entry from the map when a connection was closed.
Describe how you validated your changes
- [x] Added a UT (TestSSLMapsCleanup) to validate the change. I created a test that verifies the map is cleaned after the connection is closed. I also ran the test on the main branch to confirm that the map is not empty without the fix, and as expected, the test validates the improvement.
- [x] Run the branch on load test.
- [x] Run the branch on staging cluster.
I have created a notebook to track important metrics in order to validate that the leak was indeed resolved and to measure the impact of the change.
Results
- A major improvement was observed in the ssl_sock_by_ctx leak, which can be clearly seen in the notebook.
- No negative impact on accuracy or performance was observed due to the change, both in the staging cluster and in the load test.
- No negative impact was observed in the eBPF internal telemetry, such as the user-mode map cleaner count, etc.
Possible Drawbacks / Trade-offs
Additional Notes
Currently, this branch is based on the assumption that we are reverting PR 34981, as it handles the case where the map is not being used.
This solution was chosen to avoid changes that would significantly complicate the TLS code or introduce additional overhead.
TODO:
- [ ] Make sure that PR 34981 is reverted before merging.
Regression Detector
Regression Detector Results
Metrics dashboard
Target profiles
Run ID: 9171d329-ec0d-49ea-bf03-4bc2286986fc
Baseline: 5ebb5862e9c2650e578fda08cfe8ba791cafbe2f Comparison: 3362edda892fad233320d0269f979a4ce7c9cb48 Diff
Optimization Goals: ✅ No significant changes detected
Fine details of change detection per experiment
| perf | experiment | goal | Δ mean % | Δ mean % CI | trials | links |
|---|---|---|---|---|---|---|
| ➖ | docker_containers_memory | memory utilization | +1.06 | [+0.97, +1.16] | 1 | Logs |
| ➖ | tcp_syslog_to_blackhole | ingress throughput | +0.42 | [+0.35, +0.50] | 1 | Logs |
| ➖ | file_tree | memory utilization | +0.41 | [+0.30, +0.51] | 1 | Logs |
| ➖ | otlp_ingest_metrics | memory utilization | +0.38 | [+0.22, +0.55] | 1 | Logs |
| ➖ | docker_containers_cpu | % cpu utilization | +0.31 | [-2.74, +3.36] | 1 | Logs |
| ➖ | quality_gate_idle_all_features | memory utilization | +0.11 | [+0.04, +0.18] | 1 | Logs bounds checks dashboard |
| ➖ | file_to_blackhole_500ms_latency | egress throughput | +0.05 | [-0.54, +0.64] | 1 | Logs |
| ➖ | otlp_ingest_logs | memory utilization | +0.05 | [-0.07, +0.18] | 1 | Logs |
| ➖ | file_to_blackhole_300ms_latency | egress throughput | +0.03 | [-0.56, +0.63] | 1 | Logs |
| ➖ | file_to_blackhole_1000ms_latency_linear_load | egress throughput | +0.02 | [-0.22, +0.25] | 1 | Logs |
| ➖ | uds_dogstatsd_to_api | ingress throughput | +0.01 | [-0.27, +0.28] | 1 | Logs |
| ➖ | tcp_dd_logs_filter_exclude | ingress throughput | +0.00 | [-0.02, +0.02] | 1 | Logs |
| ➖ | file_to_blackhole_1000ms_latency | egress throughput | -0.01 | [-0.67, +0.64] | 1 | Logs |
| ➖ | file_to_blackhole_0ms_latency_http2 | egress throughput | -0.02 | [-0.60, +0.56] | 1 | Logs |
| ➖ | quality_gate_idle | memory utilization | -0.04 | [-0.12, +0.05] | 1 | Logs bounds checks dashboard |
| ➖ | file_to_blackhole_0ms_latency_http1 | egress throughput | -0.04 | [-0.67, +0.58] | 1 | Logs |
| ➖ | file_to_blackhole_100ms_latency | egress throughput | -0.05 | [-0.62, +0.52] | 1 | Logs |
| ➖ | file_to_blackhole_0ms_latency | egress throughput | -0.10 | [-0.70, +0.51] | 1 | Logs |
| ➖ | ddot_logs | memory utilization | -0.21 | [-0.30, -0.12] | 1 | Logs |
| ➖ | ddot_metrics | memory utilization | -0.26 | [-0.37, -0.14] | 1 | Logs |
| ➖ | uds_dogstatsd_20mb_12k_contexts_20_senders | memory utilization | -0.53 | [-0.58, -0.49] | 1 | Logs |
| ➖ | uds_dogstatsd_to_api_cpu | % cpu utilization | -1.17 | [-2.06, -0.27] | 1 | Logs |
| ➖ | quality_gate_logs | % cpu utilization | -2.35 | [-5.09, +0.38] | 1 | Logs bounds checks dashboard |
Bounds Checks: ✅ Passed
| perf | experiment | bounds_check_name | replicates_passed | links |
|---|---|---|---|---|
| ✅ | docker_containers_cpu | simple_check_run | 10/10 | |
| ✅ | docker_containers_memory | memory_usage | 10/10 | |
| ✅ | docker_containers_memory | simple_check_run | 10/10 | |
| ✅ | file_to_blackhole_0ms_latency | lost_bytes | 10/10 | |
| ✅ | file_to_blackhole_0ms_latency | memory_usage | 10/10 | |
| ✅ | file_to_blackhole_0ms_latency_http1 | lost_bytes | 10/10 | |
| ✅ | file_to_blackhole_0ms_latency_http1 | memory_usage | 10/10 | |
| ✅ | file_to_blackhole_0ms_latency_http2 | lost_bytes | 10/10 | |
| ✅ | file_to_blackhole_0ms_latency_http2 | memory_usage | 10/10 | |
| ✅ | file_to_blackhole_1000ms_latency | memory_usage | 10/10 | |
| ✅ | file_to_blackhole_1000ms_latency_linear_load | memory_usage | 10/10 | |
| ✅ | file_to_blackhole_100ms_latency | lost_bytes | 10/10 | |
| ✅ | file_to_blackhole_100ms_latency | memory_usage | 10/10 | |
| ✅ | file_to_blackhole_300ms_latency | lost_bytes | 10/10 | |
| ✅ | file_to_blackhole_300ms_latency | memory_usage | 10/10 | |
| ✅ | file_to_blackhole_500ms_latency | lost_bytes | 10/10 | |
| ✅ | file_to_blackhole_500ms_latency | memory_usage | 10/10 | |
| ✅ | quality_gate_idle | intake_connections | 10/10 | bounds checks dashboard |
| ✅ | quality_gate_idle | memory_usage | 10/10 | bounds checks dashboard |
| ✅ | quality_gate_idle_all_features | intake_connections | 10/10 | bounds checks dashboard |
| ✅ | quality_gate_idle_all_features | memory_usage | 10/10 | bounds checks dashboard |
| ✅ | quality_gate_logs | intake_connections | 10/10 | bounds checks dashboard |
| ✅ | quality_gate_logs | lost_bytes | 10/10 | bounds checks dashboard |
| ✅ | quality_gate_logs | memory_usage | 10/10 | bounds checks dashboard |
Explanation
Confidence level: 90.00% Effect size tolerance: |Δ mean %| ≥ 5.00%
Performance changes are noted in the perf column of each table:
- ✅ = significantly better comparison variant performance
- ❌ = significantly worse comparison variant performance
- ➖ = no significant change in performance
A regression test is an A/B test of target performance in a repeatable rig, where "performance" is measured as "comparison variant minus baseline variant" for an optimization goal (e.g., ingress throughput). Due to intrinsic variability in measuring that goal, we can only estimate its mean value for each experiment; we report uncertainty in that value as a 90.00% confidence interval denoted "Δ mean % CI".
For each experiment, we decide whether a change in performance is a "regression" -- a change worth investigating further -- if all of the following criteria are true:
-
Its estimated |Δ mean %| ≥ 5.00%, indicating the change is big enough to merit a closer look.
-
Its 90.00% confidence interval "Δ mean % CI" does not contain zero, indicating that if our statistical model is accurate, there is at least a 90.00% chance there is a difference in performance between baseline and comparison variants.
-
Its configuration does not mark it "erratic".
CI Pass/Fail Decision
✅ Passed. All Quality Gates passed.
- quality_gate_idle, bounds check intake_connections: 10/10 replicas passed. Gate passed.
- quality_gate_idle, bounds check memory_usage: 10/10 replicas passed. Gate passed.
- quality_gate_logs, bounds check memory_usage: 10/10 replicas passed. Gate passed.
- quality_gate_logs, bounds check lost_bytes: 10/10 replicas passed. Gate passed.
- quality_gate_logs, bounds check intake_connections: 10/10 replicas passed. Gate passed.
- quality_gate_idle_all_features, bounds check memory_usage: 10/10 replicas passed. Gate passed.
- quality_gate_idle_all_features, bounds check intake_connections: 10/10 replicas passed. Gate passed.
Static quality checks
✅ Please find below the results from static quality gates Comparison made with ancestor 5ebb5862e9c2650e578fda08cfe8ba791cafbe2f
Successful checks
Info
| Quality gate | Delta | On disk size (MiB) | Delta | On wire size (MiB) | |
|---|---|---|---|---|---|
| ✅ | agent_deb_amd64 | $${+0.09}$$ | $${700.46}$$ < $${700.55}$$ | $${-0.05}$$ | $${176.61}$$ < $${177.62}$$ |
| ✅ | agent_deb_amd64_fips | $${+0.09}$$ | $${698.73}$$ < $${699.75}$$ | $${-0.01}$$ | $${176.09}$$ < $${177.04}$$ |
| ✅ | agent_heroku_amd64 | $${0}$$ | $${352.29}$$ < $${362.84}$$ | $${+0.01}$$ | $${95.11}$$ < $${98.91}$$ |
| ✅ | agent_msi | $${0}$$ | $${973.36}$$ < $${973.9}$$ | $${+0}$$ | $${147.12}$$ < $${148.11}$$ |
| ✅ | agent_rpm_amd64 | $${+0.09}$$ | $${700.45}$$ < $${700.53}$$ | $${+0.04}$$ | $${178.35}$$ < $${179.2}$$ |
| ✅ | agent_rpm_amd64_fips | $${+0.09}$$ | $${698.72}$$ < $${699.74}$$ | $${+0.02}$$ | $${177.87}$$ < $${178.75}$$ |
| ✅ | agent_rpm_arm64 | $${+0.09}$$ | $${690.32}$$ < $${690.5}$$ | $${+0.02}$$ | $${161.74}$$ < $${162.56}$$ |
| ✅ | agent_rpm_arm64_fips | $${+0.09}$$ | $${688.7}$$ < $${689.8}$$ | $${+0.02}$$ | $${160.81}$$ < $${161.61}$$ |
| ✅ | agent_suse_amd64 | $${+0.09}$$ | $${700.45}$$ < $${700.54}$$ | $${+0.04}$$ | $${178.35}$$ < $${179.2}$$ |
| ✅ | agent_suse_amd64_fips | $${+0.09}$$ | $${698.72}$$ < $${699.74}$$ | $${+0.02}$$ | $${177.87}$$ < $${178.93}$$ |
| ✅ | agent_suse_arm64 | $${+0.09}$$ | $${690.32}$$ < $${690.43}$$ | $${+0.02}$$ | $${161.74}$$ < $${162.57}$$ |
| ✅ | agent_suse_arm64_fips | $${+0.09}$$ | $${688.7}$$ < $${689.78}$$ | $${+0.02}$$ | $${160.81}$$ < $${161.61}$$ |
| ✅ | docker_agent_amd64 | $${+0.09}$$ | $${784.26}$$ < $${784.33}$$ | $${+0.01}$$ | $${269.74}$$ < $${270.56}$$ |
| ✅ | docker_agent_arm64 | $${+0.09}$$ | $${797.58}$$ < $${797.68}$$ | $${+0.02}$$ | $${257.04}$$ < $${257.84}$$ |
| ✅ | docker_agent_jmx_amd64 | $${+0.09}$$ | $${975.46}$$ < $${975.52}$$ | $${+0.02}$$ | $${338.72}$$ < $${339.53}$$ |
| ✅ | docker_agent_jmx_arm64 | $${+0.09}$$ | $${977.37}$$ < $${977.47}$$ | $${+0.01}$$ | $${321.98}$$ < $${322.81}$$ |
| ✅ | docker_agent_windows1809 | $${+0}$$ | $${1185.03}$$ < $${1190.0}$$ | $${+0.03}$$ | $${417.4}$$ < $${422.66}$$ |
| ✅ | docker_agent_windows1809_core | $${+0}$$ | $${5914.99}$$ < $${5919.41}$$ | $${0}$$ | $${2048.0}$$ < $${2049.0}$$ |
| ✅ | docker_agent_windows1809_core_jmx | $${-0}$$ | $${6036.56}$$ < $${6063.56}$$ | $${0}$$ | $${2048.0}$$ < $${2049.0}$$ |
| ✅ | docker_agent_windows1809_jmx | $${+0.13}$$ | $${1306.72}$$ < $${1311.1}$$ | $${-0.29}$$ | $${459.45}$$ < $${464.35}$$ |
| ✅ | docker_agent_windows2022 | $${+0}$$ | $${1204.33}$$ < $${1208.75}$$ | $${+0.02}$$ | $${430.14}$$ < $${434.91}$$ |
| ✅ | docker_agent_windows2022_core | $${-0}$$ | $${5888.05}$$ < $${5892.66}$$ | $${0}$$ | $${2048.0}$$ < $${2049.0}$$ |
| ✅ | docker_agent_windows2022_core_jmx | $${-0}$$ | $${6009.7}$$ < $${6014.08}$$ | $${0}$$ | $${2048.0}$$ < $${2049.0}$$ |
| ✅ | docker_agent_windows2022_jmx | $${+0.13}$$ | $${1326.05}$$ < $${1330.39}$$ | $${+0.01}$$ | $${472.39}$$ < $${477.17}$$ |
| ✅ | docker_cluster_agent_amd64 | $${0}$$ | $${213.64}$$ < $${214.5}$$ | $${-0}$$ | $${72.6}$$ < $${73.51}$$ |
| ✅ | docker_cluster_agent_arm64 | $${0}$$ | $${229.45}$$ < $${230.33}$$ | $${+0}$$ | $${68.86}$$ < $${69.77}$$ |
| ✅ | docker_cws_instrumentation_amd64 | $${0}$$ | $${7.08}$$ < $${7.12}$$ | $${-0}$$ | $${2.95}$$ < $${3.29}$$ |
| ✅ | docker_cws_instrumentation_arm64 | $${0}$$ | $${6.69}$$ < $${6.92}$$ | $${-0}$$ | $${2.7}$$ < $${3.07}$$ |
| ✅ | docker_dogstatsd_amd64 | $${0}$$ | $${39.23}$$ < $${39.57}$$ | $${+0}$$ | $${15.12}$$ < $${15.76}$$ |
| ✅ | docker_dogstatsd_arm64 | $${+0}$$ | $${37.88}$$ < $${38.2}$$ | $${+0}$$ | $${14.53}$$ < $${14.83}$$ |
| ✅ | dogstatsd_deb_amd64 | $${0}$$ | $${30.46}$$ < $${31.4}$$ | $${+0}$$ | $${8.0}$$ < $${8.95}$$ |
| ✅ | dogstatsd_deb_arm64 | $${0}$$ | $${29.03}$$ < $${29.97}$$ | $${+0}$$ | $${6.94}$$ < $${7.89}$$ |
| ✅ | dogstatsd_rpm_amd64 | $${0}$$ | $${30.46}$$ < $${31.4}$$ | $${-0}$$ | $${8.01}$$ < $${8.96}$$ |
| ✅ | dogstatsd_suse_amd64 | $${0}$$ | $${30.46}$$ < $${31.4}$$ | $${-0}$$ | $${8.01}$$ < $${8.96}$$ |
| ✅ | iot_agent_deb_amd64 | $${0}$$ | $${53.7}$$ < $${54.55}$$ | $${+0}$$ | $${13.52}$$ < $${14.45}$$ |
| ✅ | iot_agent_deb_arm64 | $${0}$$ | $${51.05}$$ < $${51.9}$$ | $${+0}$$ | $${11.7}$$ < $${12.63}$$ |
| ✅ | iot_agent_deb_armhf | $${0}$$ | $${50.57}$$ < $${51.42}$$ | $${+0}$$ | $${11.8}$$ < $${12.74}$$ |
| ✅ | iot_agent_rpm_amd64 | $${0}$$ | $${53.7}$$ < $${54.55}$$ | $${+0}$$ | $${13.54}$$ < $${14.47}$$ |
| ✅ | iot_agent_rpm_arm64 | $${0}$$ | $${51.05}$$ < $${51.91}$$ | $${-0}$$ | $${11.72}$$ < $${12.65}$$ |
| ✅ | iot_agent_suse_amd64 | $${0}$$ | $${53.7}$$ < $${54.55}$$ | $${+0}$$ | $${13.54}$$ < $${14.47}$$ |
/merge
View all feedbacks in Devflow UI.
2025-06-30 13:15:57 UTC :information_source: Start processing command /merge
2025-06-30 13:16:15 UTC :information_source: MergeQueue: waiting for PR to be ready
This merge request is not mergeable yet, because of pending checks/missing approvals. It will be added to the queue as soon as checks pass and/or get approvals.
Note: if you pushed new commits since the last approval, you may need additional approval.
You can remove it from the waiting list with /remove command.
2025-06-30 17:17:05 UTC :warning: MergeQueue: This merge request was unqueued
devflow unqueued this merge request: It did not become mergeable within the expected time
/merge
View all feedbacks in Devflow UI.
2025-07-01 13:33:20 UTC :information_source: Start processing command /merge
2025-07-01 13:33:31 UTC :information_source: MergeQueue: waiting for PR to be ready
This merge request is not mergeable yet, because of pending checks/missing approvals. It will be added to the queue as soon as checks pass and/or get approvals.
Note: if you pushed new commits since the last approval, you may need additional approval.
You can remove it from the waiting list with /remove command.
2025-07-01 14:52:18 UTC :information_source: MergeQueue: merge request added to the queue
The expected merge time in main is approximately 57m (p90).
2025-07-01 15:38:39 UTC :information_source: MergeQueue: This merge request was merged