← Back to Pull requests

fix(usm): Stop losing Go TLS HTTP transactions to a write/read race #61576

Closed
unknown closed this pull request without merging on Dec 01, 2026 08:46 UTC
View on GitHub
unknown unknown commented on Nov 27, 2026 17:07 UTC
Author

What does this PR do?


Process crypto/tls.(Conn).Write on entry rather than on return, so that USM records a Go TLS request before its bytes reach the socket, hence before its response can be read.

Process each call once, as the entry probe fires again when the prologue restarts, and let the return probe only forget the call.

Drop the then unused write return offsets.

Add TestGoTLSWriteParsedOncePerCall, which makes Go TLS writes at growing stack depths and checks each one is parsed exactly once.

Add a release note.

Motivation


TestHTTPScenarios/
/with_TLS/TestSimple subtests have been flaky since they were added, failing in about 1 to 5% of the runs, more often with more client connections, and never without TLS, as tracked in _Flaky Test Management_ and Jira:

| First seen | Subtest of TestHTTPScenarios | FTM | Jira |
|---|---|---|---|
| 2025-07-08 09:57 | CO-RE/with_TLS/TestSimple | DD_JOI8TK | [CIMP-15050] |
| 2025-07-08 09:57 | CO-RE/with_TLS/TestSimple/IPv4 | DD_09VQTW | [CIMP-15052] |
| 2025-07-08 14:21 | runtime_compiled/with_TLS/TestSimple/IPv4 | DD_O2QNJL | [CIMP-15046] |
| 2025-07-08 14:21 | runtime_compiled/with_TLS/TestSimple | DD_ENUH4B | |
| 2025-07-08 14:30 | runtime_compiled/with_TLS/TestSimple/IPv6 | DD_1YA4VM | [CIMP-15056] |
| 2025-07-08 14:43 | CO-RE/with_TLS/TestSimple/IPv4/multiple_get_requests-different_clients_-_5 | DD_UCXUT1 | [CIMP-15053] |
| 2025-07-08 14:43 | runtime_compiled/with_TLS/TestSimple/IPv4/multiple_get_requests-different_clients_-_5 | DD_VRW5TS | [CIMP-15047] |
| 2025-07-08 14:59 | CO-RE/with_TLS/TestSimple/IPv6 | DD_Y6ND9M | [CIMP-15051] |
| 2025-07-08 17:22 | runtime_compiled/with_TLS/TestSimple/IPv6/multiple_get_requests-different_clients_-_5 | DD_1YS7ZM | [CIMP-15063] |
| 2025-07-08 17:30 | CO-RE/with_TLS/TestSimple/IPv6/multiple_get_requests-different_clients_-_5 | DD_HU2BOE | [CIMP-15049] |
| 2025-07-08 17:59 | CO-RE/with_TLS/TestSimple/IPv6/multiple_get_requests-different_clients_-_1 | DD_19U14K | [CIMP-15068] |
| 2025-07-08 18:03 | CO-RE/with_TLS/TestSimple/IPv4/multiple_get_requests-different_clients_-_1 | DD_6Y56MI | [CIMP-15054] |
| 2025-07-08 18:04 | runtime_compiled/with_TLS/TestSimple/IPv6/multiple_get_requests-different_clients_-_1 | DD_O3EQV7 | [CIMP-15059] |
| 2025-07-08 18:09 | runtime_compiled/with_TLS/TestSimple/IPv4/multiple_get_requests-different_clients_-_2 | DD_MNM75G | [CIMP-15057] |
| 2025-07-08 18:45 | runtime_compiled/with_TLS/TestSimple/IPv4/multiple_get_requests-different_clients_-_1 | DD_4IM0K0 | [CIMP-15058] |
| 2025-07-08 18:45 | runtime_compiled/with_TLS/TestSimple/IPv6/multiple_get_requests-different_clients_-_2 | DD_5UDT8A | [CIMP-15055] |
| 2025-07-08 19:44 | CO-RE/with_TLS/TestSimple/IPv6/multiple_get_requests-different_clients_-_2 | DD_CXBT23 | [CIMP-15060] |
| 2025-07-08 20:55 | CO-RE/with_TLS/TestSimple/IPv4/multiple_get_requests-different_clients_-_2 | DD_ZJNLIQ | [CIMP-15062] |
| 2026-03-25 11:14 | prebuilt/with_TLS/TestSimple/IPv6/multiple_get_requests-different_clients_-_1 | | [CIMP-16906] |
| 2026-04-03 18:45 | prebuilt/with_TLS/TestSimple/IPv4/multiple_get_requests-different_clients_-_1 | | [CIMP-16912] |

With extra debug logs, a failing run shows 2 proxy threads handling a request and its response on the same connection at the same time, both flushing the previous transaction, after which the connection closes on a request without response, e.g. in https://gitlab.ddbuild.io/DataDog/datadog-agent/-/jobs/2305514577:

2749.247623 external_unix_p-30813: http_enqueue: status 200 sport 36314 dport 8089
2749.247624 external_unix_p-30813: http_process: type=2 method=0
2749.247627 external_unix_p-30819: http_enqueue: status 200 sport 36314 dport 8089
2749.247628 external_unix_p-30819: http_process: type=1 method=1
[...]
2749.248950 external_unix_p-30815: http_termination: status 0 tcp_seq 0 started 1
2749.248952 external_unix_p-30815: http_enqueue: status 0 sport 36314 dport 8089

No such status 0 transaction reaches the stats, so the test counts 9 requests out of 10.

The request was processed in Write/return, i.e. after its bytes were sent, so the goroutine reading the response could reach Read/return first, both updating the same http_in_flight entry unsynchronized.

Any Go TLS client reading and writing from different goroutines is affected, not only the test.

Processing on entry alone parsed some requests 2 or 3 times, as the prologue of a Go function jumps back to the function start after runtime.morestack grows its stack or serves a preemption request (stacksplit in cmd/internal/obj/x86/obj6.go and cmd/internal/obj/arm64/obj7.go), e.g. in https://gitlab.ddbuild.io/DataDog/datadog-agent/-/jobs/2307596069:

1821.983416 external_unix_p-71876: DIAG go-tls-write conn 17115eac9888 len 104
1821.983426 external_unix_p-71876: DIAG kafka count api_key 1 correlation_id 1 topic_size 10
1821.983491 external_unix_p-71886: DIAG go-tls-write conn 17115eac9888 len 104
1821.983499 external_unix_p-71886: DIAG kafka count api_key 1 correlation_id 1 topic_size 10

Describe how you validated your changes


The usm objects build for x86_64 and aarch64, debug variants included, and dda inv linter.go passes on the changed packages.

Repeating the TestSimple subtests 10 times on the KMT VMs went from 11 lost requests in 480 runs to none in 3,120 runs, e.g. in https://gitlab.ddbuild.io/DataDog/datadog-agent/-/pipelines/156822740.

TestGoTLSWriteParsedOncePerCall passes in the 27 KMT jobs supporting Go TLS, e.g. in https://gitlab.ddbuild.io/DataDog/datadog-agent/-/pipelines/156959534, and fails in all of them without the per call check, counting 2,006 to 2,009 parses of 2,000 writes, e.g. in https://gitlab.ddbuild.io/DataDog/datadog-agent/-/pipelines/156947457.

Additional Notes


A write failing after its entry is now parsed, whereas the return probe ignored it.
For a client, whose write is the request, it only shows in kernel telemetry counting requests, such as Kafka's topic name sizes, since HTTP, HTTP/2, Kafka, Postgres, and Redis only report a transaction with its response.
For a server, whose write is the response, the status of a response that failed to be written is now reported.

Writes are parsed in the order goroutines enter Write, before crypto/tls takes its output lock, so concurrent writes on a same connection can be parsed in another order than sent, which net/http and kgo avoid by writing one at a time.

A Write exiting without its return probe, as on a panic, gets the next Write of its goroutine with the same connection, buffer, and length skipped as a prologue restart.

The whole buffer is parsed instead of the written bytes, which only differ when Write returns an error, possibly after sending some of its records.

The connection tuple is available on entry since it is read from the dialed net.TCPConn, not from the TLS handshake.

[CIMP-15046]: https://datadoghq.atlassian.net/browse/CIMP-15046?atlOrigin=eyJpIjoiNWRkNTljNzYxNjVmNDY3MDlhMDU5Y2ZhYzA5YTRkZjUiLCJwIjoiZ2l0aHViLWNvbS1KU1cifQ
[CIMP-15047]: https://datadoghq.atlassian.net/browse/CIMP-15047?atlOrigin=eyJpIjoiNWRkNTljNzYxNjVmNDY3MDlhMDU5Y2ZhYzA5YTRkZjUiLCJwIjoiZ2l0aHViLWNvbS1KU1cifQ
[CIMP-15049]: https://datadoghq.atlassian.net/browse/CIMP-15049?atlOrigin=eyJpIjoiNWRkNTljNzYxNjVmNDY3MDlhMDU5Y2ZhYzA5YTRkZjUiLCJwIjoiZ2l0aHViLWNvbS1KU1cifQ
[CIMP-15050]: https://datadoghq.atlassian.net/browse/CIMP-15050?atlOrigin=eyJpIjoiNWRkNTljNzYxNjVmNDY3MDlhMDU5Y2ZhYzA5YTRkZjUiLCJwIjoiZ2l0aHViLWNvbS1KU1cifQ
[CIMP-15051]: https://datadoghq.atlassian.net/browse/CIMP-15051?atlOrigin=eyJpIjoiNWRkNTljNzYxNjVmNDY3MDlhMDU5Y2ZhYzA5YTRkZjUiLCJwIjoiZ2l0aHViLWNvbS1KU1cifQ
[CIMP-15052]: https://datadoghq.atlassian.net/browse/CIMP-15052?atlOrigin=eyJpIjoiNWRkNTljNzYxNjVmNDY3MDlhMDU5Y2ZhYzA5YTRkZjUiLCJwIjoiZ2l0aHViLWNvbS1KU1cifQ
[CIMP-15053]: https://datadoghq.atlassian.net/browse/CIMP-15053?atlOrigin=eyJpIjoiNWRkNTljNzYxNjVmNDY3MDlhMDU5Y2ZhYzA5YTRkZjUiLCJwIjoiZ2l0aHViLWNvbS1KU1cifQ
[CIMP-15054]: https://datadoghq.atlassian.net/browse/CIMP-15054?atlOrigin=eyJpIjoiNWRkNTljNzYxNjVmNDY3MDlhMDU5Y2ZhYzA5YTRkZjUiLCJwIjoiZ2l0aHViLWNvbS1KU1cifQ
[CIMP-15055]: https://datadoghq.atlassian.net/browse/CIMP-15055?atlOrigin=eyJpIjoiNWRkNTljNzYxNjVmNDY3MDlhMDU5Y2ZhYzA5YTRkZjUiLCJwIjoiZ2l0aHViLWNvbS1KU1cifQ
[CIMP-15056]: https://datadoghq.atlassian.net/browse/CIMP-15056?atlOrigin=eyJpIjoiNWRkNTljNzYxNjVmNDY3MDlhMDU5Y2ZhYzA5YTRkZjUiLCJwIjoiZ2l0aHViLWNvbS1KU1cifQ
[CIMP-15057]: https://datadoghq.atlassian.net/browse/CIMP-15057?atlOrigin=eyJpIjoiNWRkNTljNzYxNjVmNDY3MDlhMDU5Y2ZhYzA5YTRkZjUiLCJwIjoiZ2l0aHViLWNvbS1KU1cifQ
[CIMP-15058]: https://datadoghq.atlassian.net/browse/CIMP-15058?atlOrigin=eyJpIjoiNWRkNTljNzYxNjVmNDY3MDlhMDU5Y2ZhYzA5YTRkZjUiLCJwIjoiZ2l0aHViLWNvbS1KU1cifQ
[CIMP-15059]: https://datadoghq.atlassian.net/browse/CIMP-15059?atlOrigin=eyJpIjoiNWRkNTljNzYxNjVmNDY3MDlhMDU5Y2ZhYzA5YTRkZjUiLCJwIjoiZ2l0aHViLWNvbS1KU1cifQ
[CIMP-15060]: https://datadoghq.atlassian.net/browse/CIMP-15060?atlOrigin=eyJpIjoiNWRkNTljNzYxNjVmNDY3MDlhMDU5Y2ZhYzA5YTRkZjUiLCJwIjoiZ2l0aHViLWNvbS1KU1cifQ
[CIMP-15062]: https://datadoghq.atlassian.net/browse/CIMP-15062?atlOrigin=eyJpIjoiNWRkNTljNzYxNjVmNDY3MDlhMDU5Y2ZhYzA5YTRkZjUiLCJwIjoiZ2l0aHViLWNvbS1KU1cifQ
[CIMP-15063]: https://datadoghq.atlassian.net/browse/CIMP-15063?atlOrigin=eyJpIjoiNWRkNTljNzYxNjVmNDY3MDlhMDU5Y2ZhYzA5YTRkZjUiLCJwIjoiZ2l0aHViLWNvbS1KU1cifQ
[CIMP-15068]: https://datadoghq.atlassian.net/browse/CIMP-15068?atlOrigin=eyJpIjoiNWRkNTljNzYxNjVmNDY3MDlhMDU5Y2ZhYzA5YTRkZjUiLCJwIjoiZ2l0aHViLWNvbS1KU1cifQ
[CIMP-16906]: https://datadoghq.atlassian.net/browse/CIMP-16906?atlOrigin=eyJpIjoiNWRkNTljNzYxNjVmNDY3MDlhMDU5Y2ZhYzA5YTRkZjUiLCJwIjoiZ2l0aHViLWNvbS1KU1cifQ
[CIMP-16912]: https://datadoghq.atlassian.net/browse/CIMP-16912?atlOrigin=eyJpIjoiNWRkNTljNzYxNjVmNDY3MDlhMDU5Y2ZhYzA5YTRkZjUiLCJwIjoiZ2l0aHViLWNvbS1KU1cifQ

Diff: 650 lines (+487 / -163) across 8 files Reviewer: brycekahle Review duration: 5259m
All Vouch review confidence checks passed
Residual risk 0.30 = Change Risk (0.75) × (1 − Review Confidence (0.60)). Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.75 · 650 lines diff across 8 files
0.75
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.17 · 1 substantive comment(s)
0.17
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 35%
60%
Bedrock Claude 3 · Risk Narration
(disconnected)
Groq
Groq Risk Narration
AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
Model 1 · Change Risk Attribution
SHAP Weights
Diff Size diff_size
0.388
Shallow Review Depth shallow_review_depth
0.289
Sensitive Paths sensitive_paths
0.075
Real PR Conversation Timeline
1 comments
"Review active on #61576"
general weight: 0.35
Reviewers
Assignees
Unassigned
Labels
risk: low confidence: 60.5% reviewed sensitive_module
Vouch Risk Breakdown
AI-powered review risk analysis
Change Risk
Change Risk · Model 1 (XGBoost)
Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
Score: 75.2% (HIGH) · Higher = larger blast radius
75.2%
Review Confidence
Review Confidence · Models 2 & 3
Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
Score: 60.5% · Lower = rushed or shallow review
60.5%
Residual Risk
Residual Risk · Core Equation
Residual = Change × (1 − Confidence)
Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
Score: 29.7% · Safe to merge
29.7%