Skip to content

feat: fix keeping query plan dispatch checks through singleflight#3119

Open
barakmich wants to merge 1 commit into
mainfrom
barakmich/singleflight
Open

feat: fix keeping query plan dispatch checks through singleflight#3119
barakmich wants to merge 1 commit into
mainfrom
barakmich/singleflight

Conversation

@barakmich
Copy link
Copy Markdown
Contributor

Description

We have singleflight, but it doesn't have a group for query plans. Check is the most meaningful one here (same reason we don't have a group for LR or LS) so let's make checks singleflight-able

@barakmich barakmich requested a review from a team as a code owner May 13, 2026 22:29
@github-actions github-actions Bot added area/tooling Affects the dev or user toolchain (e.g. tests, ci, build tools) area/dispatch Affects dispatching of requests labels May 13, 2026
@codecov
Copy link
Copy Markdown

codecov Bot commented May 13, 2026

Codecov Report

❌ Patch coverage is 63.63636% with 12 lines in your changes missing coverage. Please review.
✅ Project coverage is 75.68%. Comparing base (8a01e69) to head (a5fb8e1).

Files with missing lines Patch % Lines
internal/dispatch/singleflight/singleflight.go 63.64% 8 Missing and 4 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #3119      +/-   ##
==========================================
+ Coverage   75.68%   75.68%   +0.01%     
==========================================
  Files         502      502              
  Lines       61989    62017      +28     
==========================================
+ Hits        46909    46932      +23     
- Misses      11665    11669       +4     
- Partials     3415     3416       +1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Copy link
Copy Markdown

@github-actions github-actions Bot left a comment

Choose a reason for hiding this comment

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

⚠️ Performance Alert ⚠️

Possible performance regression was detected for benchmark.
Benchmark result of this commit is worse than the previous benchmark result exceeding threshold 2.

Benchmark suite Current: a5fb8e1 Previous: 8a01e69 Ratio
BenchmarkDatastoreDriver/cockroachdb-overlap-static/TestTuple/SnapshotReverseRead (github.com/authzed/spicedb/internal/datastore/benchmark) 43288767 ns/op 173980 B/op 20198 allocs/op 7033740 ns/op 172723 B/op 20195 allocs/op 6.15
BenchmarkDatastoreDriver/cockroachdb-overlap-static/TestTuple/SnapshotReverseRead (github.com/authzed/spicedb/internal/datastore/benchmark) - ns/op 43288767 ns/op 7033740 ns/op 6.15
BenchmarkDatastoreDriver/cockroachdb-overlap-insecure/TestTuple/SnapshotReverseRead (github.com/authzed/spicedb/internal/datastore/benchmark) 42906143 ns/op 172537 B/op 20195 allocs/op 7027604 ns/op 172707 B/op 20195 allocs/op 6.11
BenchmarkDatastoreDriver/cockroachdb-overlap-insecure/TestTuple/SnapshotReverseRead (github.com/authzed/spicedb/internal/datastore/benchmark) - ns/op 42906143 ns/op 7027604 ns/op 6.11
BenchmarkDatastoreDriver/cockroachdb-overlap-insecure/TestTuple/Touch (github.com/authzed/spicedb/internal/datastore/benchmark) 6029042 ns/op 22180 B/op 287 allocs/op 2954634 ns/op 22021 B/op 287 allocs/op 2.04
BenchmarkDatastoreDriver/cockroachdb-overlap-insecure/TestTuple/Touch (github.com/authzed/spicedb/internal/datastore/benchmark) - ns/op 6029042 ns/op 2954634 ns/op 2.04
BenchmarkDatastoreDriver/cockroachdb-overlap-insecure/TestTuple/Create (github.com/authzed/spicedb/internal/datastore/benchmark) 5833145 ns/op 19551 B/op 281 allocs/op 2743304 ns/op 19496 B/op 281 allocs/op 2.13
BenchmarkDatastoreDriver/cockroachdb-overlap-insecure/TestTuple/Create (github.com/authzed/spicedb/internal/datastore/benchmark) - ns/op 5833145 ns/op 2743304 ns/op 2.13

This comment was automatically generated by workflow using github-action-benchmark.

Copy link
Copy Markdown
Contributor

@tstirrat15 tstirrat15 left a comment

Choose a reason for hiding this comment

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

See comments

Comment on lines +154 to +157
// single-value singleflight model. Recursion safety is provided by the
// receiver-side DispatchExecutor, which refuses to dispatch any alias
// whose key is already in PlanContext.in_progress_keys, so a plan-check
// can never recurse to itself with the same dispatch key.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

With the potential issue here being a singleflight deadlock if this guarantee isn't present?

assertCounterWithLabel(t, reg, 1, "spicedb_dispatch_single_flight_total", "DispatchQueryPlan")
}

func TestDispatchQueryPlanCheckCoalescesConcurrentCalls(t *testing.T) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

If this isn't talking to a datastore, this would be a good candidate for synctest.

@barakmich barakmich force-pushed the barakmich/singleflight branch from ed3b15d to a5fb8e1 Compare May 15, 2026 16:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/dispatch Affects dispatching of requests area/tooling Affects the dev or user toolchain (e.g. tests, ci, build tools)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants