Skip to content

[9.3] (backport #19948) tbs: Fix potential data race#20140

Merged
mergify[bot] merged 3 commits into9.3from
mergify/bp/9.3/pr-19948
Feb 17, 2026
Merged

[9.3] (backport #19948) tbs: Fix potential data race#20140
mergify[bot] merged 3 commits into9.3from
mergify/bp/9.3/pr-19948

Conversation

@mergify
Copy link
Contributor

@mergify mergify bot commented Jan 16, 2026

Summary

Fix potential data race between WriteTraceEvent in ProcessBatch and ReadTraceEvent in the sampling goroutine. Closes #17772.

Performance

Baseline

goos: darwin
goarch: arm64
pkg: github.com/elastic/apm-server/x-pack/apm-server/sampling
cpu: Apple M4 Pro
BenchmarkProcess-14              3096828               357.5 ns/op
BenchmarkProcess-14              3284749               359.1 ns/op
BenchmarkProcess-14              3191538               353.3 ns/op
BenchmarkProcess-14              3333675               345.3 ns/op
BenchmarkProcess-14              3331615               345.4 ns/op
BenchmarkProcess-100             3439828               344.9 ns/op
BenchmarkProcess-100             3526257               325.7 ns/op
BenchmarkProcess-100             3461000               322.2 ns/op
BenchmarkProcess-100             3480249               394.0 ns/op
BenchmarkProcess-100             2877158               608.7 ns/op

Single Mutex

goos: darwin
goarch: arm64
pkg: github.com/elastic/apm-server/x-pack/apm-server/sampling
cpu: Apple M4 Pro
BenchmarkProcess-14              3323389               337.5 ns/op
BenchmarkProcess-14              3482792               347.8 ns/op
BenchmarkProcess-14              3349486               333.5 ns/op
BenchmarkProcess-14              3437163               334.9 ns/op
BenchmarkProcess-14              3362293               333.8 ns/op
BenchmarkProcess-100             3516130               331.9 ns/op
BenchmarkProcess-100             3251674               339.8 ns/op
BenchmarkProcess-100             3432068               333.6 ns/op
BenchmarkProcess-100             3561802               368.2 ns/op
BenchmarkProcess-100             3290845               416.4 ns/op

ShardLockReadWriter

goos: darwin
goarch: arm64
pkg: github.com/elastic/apm-server/x-pack/apm-server/sampling
cpu: Apple M4 Pro
BenchmarkProcess-14              3272188               346.3 ns/op
BenchmarkProcess-14              3415772               330.7 ns/op
BenchmarkProcess-14              3487447               333.2 ns/op
BenchmarkProcess-14              3470158               337.4 ns/op
BenchmarkProcess-14              3467367               338.6 ns/op
BenchmarkProcess-100             3626730               319.7 ns/op
BenchmarkProcess-100             3722044               369.1 ns/op
BenchmarkProcess-100             3123934               349.0 ns/op
BenchmarkProcess-100             3771914               381.9 ns/op
BenchmarkProcess-100             3462182               340.4 ns/op

ShardLockReadWriter with RWMutex

goos: darwin
goarch: arm64
pkg: github.com/elastic/apm-server/x-pack/apm-server/sampling
cpu: Apple M4 Pro
BenchmarkProcess-14              3384834               343.1 ns/op
BenchmarkProcess-14              3284800               338.6 ns/op
BenchmarkProcess-14              3483038               348.2 ns/op
BenchmarkProcess-14              3217903               343.9 ns/op
BenchmarkProcess-14              3444128               334.4 ns/op
BenchmarkProcess-100             3115171               328.8 ns/op
BenchmarkProcess-100             3383545               329.2 ns/op
BenchmarkProcess-100             3069316               328.6 ns/op
BenchmarkProcess-100             3483396               334.0 ns/op
BenchmarkProcess-100             3359440               345.3 ns/op
```<hr>This is an automatic backport of pull request #19948 done by [Mergify](https://mergify.com).
* Add test confirming the potential data race

* Remove unnecessary sleeps

* Add assertion for transaction ids at the end

* Add parent id to transaction2

* Update potential race condition test

* Try fixing race condition

* Fix bug where multiple ongoing trasactions can race to delete first

* Add ShardLockReadWriter

* Panic if numShards <= 0

* Remove unnecessary code

* Use RWMutex

* Make fmt

* Add shard lock on processor level instead

* Make fmt update

* Revert "Make fmt update"

This reverts commit b788c3f.

* Update based on review

(cherry picked from commit 67a5a2b)
@mergify mergify bot added the backport label Jan 16, 2026
@mergify mergify bot requested a review from a team as a code owner January 16, 2026 09:49
@mergify mergify bot added the backport label Jan 16, 2026
@mergify mergify bot mentioned this pull request Jan 16, 2026
@github-actions
Copy link
Contributor

🤖 GitHub comments

Just comment with:

  • run docs-build : Re-trigger the docs validation. (use unformatted text in the comment!)
Copy link
Member

@carsonip carsonip left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

observe release schedule

@mergify
Copy link
Contributor Author

mergify bot commented Jan 19, 2026

This pull request has not been merged yet. Could you please review and merge it @ericywl? 🙏

1 similar comment
@mergify
Copy link
Contributor Author

mergify bot commented Jan 26, 2026

This pull request has not been merged yet. Could you please review and merge it @ericywl? 🙏

@mergify
Copy link
Contributor Author

mergify bot commented Feb 2, 2026

This pull request has not been merged yet. Could you please review and merge it @ericywl? 🙏

@ericywl ericywl enabled auto-merge (squash) February 4, 2026 05:41
@elasticmachine
Copy link
Contributor

💚 Build Succeeded

History

cc @ericywl

@mergify
Copy link
Contributor Author

mergify bot commented Feb 9, 2026

This pull request has not been merged yet. Could you please review and merge it @ericywl? 🙏

1 similar comment
@mergify
Copy link
Contributor Author

mergify bot commented Feb 16, 2026

This pull request has not been merged yet. Could you please review and merge it @ericywl? 🙏

@carsonip carsonip disabled auto-merge February 17, 2026 17:50
@mergify mergify bot added the queued label Feb 17, 2026
mergify bot added a commit that referenced this pull request Feb 17, 2026
@mergify
Copy link
Contributor Author

mergify bot commented Feb 17, 2026

Merge Queue Status

Rule: default


This pull request spent 8 minutes 26 seconds in the queue, including 8 minutes 14 seconds running CI.

Required conditions to merge
mergify bot added a commit that referenced this pull request Feb 17, 2026
@mergify mergify bot merged commit 87d3882 into 9.3 Feb 17, 2026
23 checks passed
@mergify mergify bot deleted the mergify/bp/9.3/pr-19948 branch February 17, 2026 17:59
@mergify mergify bot removed the queued label Feb 17, 2026
@github-actions github-actions bot mentioned this pull request Feb 19, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

3 participants