Skip to content

fix(api): resolve data race in Controller.Debug and enable race detector#2933

Draft
anyasabo wants to merge 2 commits intotphakala:mainfrom
anyasabo:fix/data-race-and-enable-race-detector
Draft

fix(api): resolve data race in Controller.Debug and enable race detector#2933
anyasabo wants to merge 2 commits intotphakala:mainfrom
anyasabo:fix/data-race-and-enable-race-detector

Conversation

@anyasabo
Copy link
Copy Markdown
Contributor

@anyasabo anyasabo commented May 2, 2026

Summary

Based on #2931 (CGO env vars for test tasks).

  • Fixes a data race between Controller.UpdateSectionSettings (writes c.Settings) and a goroutine spawned by handleSettingsChanges that calls Controller.Debug (reads c.Settings as fallback). The Debug method's fallback to c.Settings when conf.GetSettings() returns nil is removed -- it now returns silently, which is safe since it's purely for logging.
  • Enables the Go race detector (-race) in CI unit tests and in task test so future races are caught automatically.

Test plan

  • go test -race -short ./... passes locally with zero race warnings
  • TestDashboardLayoutWidthPersistence specifically verified with -race (was the only failing test)

The test and test-coverage tasks run `go test` without CGO_ENABLED or
CGO_CFLAGS, so the go-tflite dependency fails to compile when those
vars are not already exported in the shell. The lint task already
handles this via the CGO_FLAGS variable, but the test tasks were
missing it.

Add an env block to both tasks so `task test` works out of the box
after `task setup-dev`.

Co-authored-by: Cursor <cursoragent@cursor.com>
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 2, 2026

Important

Review skipped

Draft detected.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: f759ea55-0af6-40b1-b0cd-85b2dcb881d8

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request enables the Go race detector and CGO in the Taskfile for testing and addresses a potential race condition in the API controller's Debug method by removing an unsafe fallback to c.Settings. A review comment suggests enabling the race detector in the test-coverage task as well to maintain consistency across test commands.

Comment thread Taskfile.yml
cmds:
- mkdir -p coverage
# Use noembed,skipfrontend tags to skip model and frontend embedding for faster tests
- go test -tags noembed,skipfrontend ./... -coverprofile=coverage/coverage.out {{.TEST_FLAGS}}
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.

medium

The -race flag is missing from the test-coverage task. To ensure consistency with the pull request's objective of catching data races automatically in CI and local testing, the race detector should be enabled here as well, especially since CGO_ENABLED: "1" has already been added to the environment to support it.

      - go test -tags noembed,skipfrontend -race ./... -coverprofile=coverage/coverage.out {{.TEST_FLAGS}}

Fix a data race between Controller.UpdateSectionSettings (which writes
c.Settings) and a goroutine spawned by handleSettingsChanges that calls
Controller.Debug (which reads c.Settings as a fallback when the global
settings snapshot is nil).

The fix removes the c.Settings fallback from Debug(). When
conf.GetSettings() returns nil (standalone test Controllers that don't
set the global), Debug now returns silently instead of racing on the
unprotected field. This is safe because Debug is purely for logging.

Also enables the race detector across test invocations:
- Add -race to the CI unit test run in golangci-test.yml (with
  timeout bumped from 120s/5min to 300s/10min for race overhead)
- Add -race and CGO env vars to `task test` in Taskfile.yml so
  local runs also catch races
- Add CGO env vars to `task test-coverage` (no -race since coverage
  and race detection don't combine well)

Co-authored-by: Cursor <cursoragent@cursor.com>
@anyasabo anyasabo force-pushed the fix/data-race-and-enable-race-detector branch from f6df242 to 66b2907 Compare May 2, 2026 19:47
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