Repository navigation
Conversation
WithSpan appended the new span to the lineage slice from the parent context. When that slice had spare capacity, two spans started from the same parent wrote the same slot of one backing array, so each sibling's context saw whichever span was written last, and concurrent callers raced. In aws-sdk-go-v2 this shows up as a data race between the HTTP dialer's GetSpan and the deserialize middleware's StartSpan within one operation. Cap the slice's capacity at its length before appending, so the append always copies.
blacksoxx
left a comment
There was a problem hiding this comment.
Read the diff against main; I did not run the package here, so these are reading notes.
The full slice expression is the right tool: lineage[:len(lineage):len(lineage)] leaves no spare capacity, so append has to copy and the parent's backing array is never written through a child. PopSpan only reslices, so it stays safe, and the price is one small allocation per WithSpan on a context that already carries spans, which is what the description says. TestWithSpanSiblings reproduces the overwrite exactly as the issue describes it (three spans deep, room for a fourth, two children), and the concurrent test is what -race needs to see the write.
Nothing blocking from my side; the changelog entry follows the usual shape.
Issue #, if available:
Fixes #736.
Description of changes:
tracing.WithSpanappended the new span to the parent context's span slice. When that slice had spare capacity, two spans started from the same parent wrote the same slot of one array, so the first child's context ended up holding the second child's span, and children started concurrently raced. In aws-sdk-go-v2 those children areDoHTTPRequestandOperationDeserializer, and the HTTP dialer reads the first in a goroutine of its own.This caps the slice's capacity at its length before appending, so the append always copies.
PopSpanonly reslices, so no context now writes into an array that another context can see. The cost is that eachWithSpanon a context that already has spans allocates a new array, a few interface values long.Testing
TestWithSpanSiblingsstarts two children from a parent three spans deep, without goroutines. Onmainit fails, the first child's context holding the second child's span (span 5 != 4); with the fix it passes.TestWithSpanSiblingsConcurrentstarts eight children from that parent at once. Onmain,go test -racefails it withDATA RACE; with the fix,go test -race -count=20 ./tracing/passes.make unit-race, which vets every module and runs its tests under-race, passes.smithyoteltracing: our race test, which fails under-raceagainst v1.28.6 without our workaround, passes against this branch. After an S3GetObject,PutObject,HeadObjectorListObjectsV2, the sent request's context now holdsDoHTTPRequest, where on v1.28.7 it holdsOperationDeserializer.The changelog entry is
.changelog/dd9b2f7f-8087-4a3c-97bc-d24ff84f79ec.json.By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
Reviewed and submitted by me, a human. The investigation, the fix and its testing were developed with the assistance of an AI coding agent.