Skip to content

test(scheduler): capture logs in a lock-guarded buffer (fixes the data race failing main) - #1443

Merged
IAmJSD merged 1 commit into
LeanerCloud:mainfrom
IAmJSD:fix/main-scheduler-log-race
Oct 26, 2026
Merged

IAmJSD merged 1 commit into
LeanerCloud:mainfrom
IAmJSD:fix/main-scheduler-log-race

Conversation

@IAmJSD

@IAmJSD IAmJSD commented Oct 26, 2026

Copy link
Copy Markdown
Collaborator

Why

main's CI failed on 89e11403 (run 40287762269): Integration Tests (migrations, rest) reported WARNING: DATA RACE in TestAWSRecommendationCompletenessPersistence/SP_empty (internal/scheduler).

The test points the process-wide logger at a plain bytes.Buffer (logging.SetOutput(&diagnostics)) and later reads diagnostics.String() (line 305). Since #1400, every subtest's database lives on one shared Postgres server, so a connection pool from an earlier subtest can still be creating idle connections in pgxpool's background goroutine (createIdleResources). Its "context canceled" connect error is logged into the current subtest's buffer while the test reads it. That's a real unsynchronized read/write on the buffer, so the race detector fails the run. It's timing-dependent: main's previous run (f3498548) passed.

What changed

Test-only: a small mutex-guarded lockedBuffer (Write and String) replaces the bytes.Buffer. The assertions are unchanged.

Verification

Linux, Go 1.26.10, Docker Postgres:

  • go test -race -tags integration -count=1 ./internal/scheduler/: ok
  • go test -race -tags integration -count=5 -run TestAWSRecommendationCompletenessPersistence ./internal/scheduler/: ok, with no DATA RACE reports
  • go test -race -short ./internal/scheduler/: ok; golangci-lint (integration tags) 0 issues; git-secrets clean

🤖 Generated with Claude Code

…eness test

main's Integration Tests (migrations, rest) failed on 89e1140 with a
data race in TestAWSRecommendationCompletenessPersistence/SP_empty. The
test points the process-wide logger at a plain bytes.Buffer and reads it
with String(). Since LeanerCloud#1400 puts every subtest's database on one shared
Postgres server, a connection pool from an earlier subtest can still be
creating idle connections in a background goroutine (pgxpool
createIdleResources), and its "context canceled" connect error is logged
into the current subtest's buffer while the test reads it. The race
detector fails the run. It's timing-dependent: the previous main run
passed.

Wrap the buffer in a small mutex-guarded type. Assertions unchanged.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@IAmJSD IAmJSD added priority/p1 Next up; this sprint type/bug Defect labels Oct 26, 2026
@coderabbitai

coderabbitai Bot commented Oct 26, 2026

Copy link
Copy Markdown
Contributor

Warning

Review limit reached

  • Run on-demand review

This review includes 1 billable file and costs up to $0.25.

Or wait 53 minutes for your next included review.

Check out review usage here.

View limit details

Limit details: You’ve used the included review currently available.

Learn how review limits work.

Review configuration:

Run configuration
Commits

Reviewing files that changed from the base of the PR and between 1dfd7ab and 3dba3f3.

Files selected for processing: 1
  • internal/scheduler/recommendation_completeness_integration_test.go
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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

@IAmJSD

IAmJSD commented Oct 26, 2026

Copy link
Copy Markdown
Collaborator Author

Merged by IAmJSD's agent at IAmJSD's request (acting owner): a fix for red main, merged as soon as the required checks passed on 3dba3f392432950e289fc24523a6758bd51c411c. Test-only; evidence in the PR body.

@IAmJSD
IAmJSD merged commit 5ddcae7 into LeanerCloud:main Oct 26, 2026
41 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

priority/p1 Next up; this sprint type/bug Defect

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant