fix(usm): Stop losing Go TLS HTTP transactions to a write/read race #61576
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
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.17 · 1 substantive comment(s)
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 35%
Bedrock Claude 3 · Risk Narration
(disconnected)
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
brycekahle
What does this PR do?
Process
crypto/tls.(Conn).Writeon 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/TestSimplesubtests 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:
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 reachRead/returnfirst, both updating the samehttp_in_flightentry 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.morestackgrows its stack or serves a preemption request (stacksplitincmd/internal/obj/x86/obj6.goandcmd/internal/obj/arm64/obj7.go), e.g. in https://gitlab.ddbuild.io/DataDog/datadog-agent/-/jobs/2307596069:Describe how you validated your changes
The
usmobjects build forx86_64andaarch64, debug variants included, anddda inv linter.gopasses on the changed packages.Repeating the
TestSimplesubtests 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.TestGoTLSWriteParsedOncePerCallpasses 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, beforecrypto/tlstakes its output lock, so concurrent writes on a same connection can be parsed in another order than sent, whichnet/httpandkgoavoid by writing one at a time.A
Writeexiting without its return probe, as on a panic, gets the nextWriteof 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
Writereturns 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