Skip to content

fix(scheduler): atomic-read counters in control loop#26

Merged
singchia merged 1 commit into
mainfrom
fix/scheduler-counter-race
Apr 24, 2026
Merged

fix(scheduler): atomic-read counters in control loop#26
singchia merged 1 commit into
mainfrom
fix/scheduler-counter-race

Conversation

@singchia

Copy link
Copy Markdown
Owner

Summary

control() reads countIncomingReqs and countProcessedReqs with plain loads, but worker goroutines and PublishRequest update them via atomic.AddInt64. Under the Go race detector this consistently trips a data-race warning — surfaced in singchia/geminio's race-enabled CI jobs.

Fix

Snapshot each counter with a single atomic.LoadInt64 so the diff and the baseline update see the same value, and no plain read races with a concurrent atomic write.

incoming := atomic.LoadInt64(&s.countIncomingReqs)
processed := atomic.LoadInt64(&s.countProcessedReqs)
incomingReqsDiff := incoming - s.countIncomingReqsL
processedReqsDiff := processed - s.countProcessedReqsL
s.countIncomingReqsL = incoming
s.countProcessedReqsL = processed

countIncomingReqsL / countProcessedReqsL are only touched by control() itself, so they stay plain.

Test plan

  • go test -race ./... in this repo — clean
  • go test -race ./test/integration/... in singchia/geminio with a local replace pointing at this branch — clean (previously raced)
  • Gemino unit/regression/e2e race suites — all clean with this fix

Impact

  • No behavioral change on non-race builds.
  • Safe to tag as v2.2.2 and bump downstream.

🤖 Generated with Claude Code

control() reads countIncomingReqs and countProcessedReqs with plain
loads while worker goroutines (and PublishRequest) update them via
atomic.AddInt64. Under the race detector this consistently trips a
data-race warning — surfaced downstream in singchia/geminio's race CI.

Snapshot each counter with a single atomic.LoadInt64 so both the diff
and the baseline update see the same value, and no plain read races
with a concurrent atomic write. No behavioral change on non-race
builds.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@singchia singchia merged commit 5ce9aef into main Apr 24, 2026
1 check passed
@singchia singchia deleted the fix/scheduler-counter-race branch April 24, 2026 15:58
singchia added a commit to singchia/geminio that referenced this pull request Apr 24, 2026
Picks up the scheduler counter-race fix (singchia/go-timer#26) so
gemino's -race CI stays clean without waiting on flake retries.
singchia added a commit to singchia/geminio that referenced this pull request Apr 24, 2026
* rename: geminio → gemino across module, package, brand, and assets

Renames the module to github.com/singchia/gemino, the top-level package
to `gemino`, and every `Geminio` / `geminio` mention in prose, examples,
docs, and tests. geminio.go → gemino.go and docs/geminio.png →
docs/gemino.png. No logic changes; all tests green under the new path
(unit, integration, e2e, chaos, regression, security, harness).

After this merges, the GitHub repo needs to be renamed
singchia/geminio → singchia/gemino (web settings). Old tags
v1.0 … v1.3.0-rc.1 remain indexed on the Go proxy under the old
module path and keep working for existing consumers; new tags under
the new path resume at v1.3.0-rc.2.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>

* make: wire up bench target and expand test coverage

- Top-level: \`make bench\` now actually runs the benchmark suite
  (README has been pointing at it for a while).
- \`make test\` no longer means just regression — it runs every suite
  under test/ (unit, integration, regression, e2e, security, harness,
  chaos). Each target gets an explicit timeout so a hang surfaces fast.

Local on Apple M4: make test ~3m14s, make bench ~1m49s. All green.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>

* chore: re-trigger CI after rename race-detector flake

* deps: bump singchia/go-timer/v2 to v2.2.2

Picks up the scheduler counter-race fix (singchia/go-timer#26) so
gemino's -race CI stays clean without waiting on flake retries.

---------

Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant