Skip to content

fix(events): synchronize drainer status reads - #6850

Open
chenrui333 wants to merge 1 commit into
mainfrom
fix/drainer-status-race
Open

fix(events): synchronize drainer status reads#6850
chenrui333 wants to merge 1 commit into
mainfrom
fix/drainer-status-race

Conversation

@chenrui333

Copy link
Copy Markdown
Member

What

Protect drainer status snapshots with the existing mutex and add concurrent polling coverage.

Why

Status requests and shutdown logging can read operation counts while commands update them.

Testing

Drainer regression fails under -race before the fix; 20 repetitions and the events package pass.

Copilot AI lite review requested due to automatic review settings September 7, 2026 06:45
@github-actions github-actions Bot added go Pull requests that update Go code size/s and removed go Pull requests that update Go code labels Sep 7, 2026

Copilot AI left a comment

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.

🟡 Changes recommended

The new TestDrainer_ConcurrentStatus uses sync.WaitGroup.Go, which doesn’t exist and will not compile.

Once you've addressed the issues Copilot identified, you can request another Copilot review.

Pull request overview

This PR hardens the events.Drainer concurrency model by ensuring status snapshots are read under the same mutex used for updates, and it updates tests to better exercise shutdown and concurrent status polling.

Changes:

  • Synchronize Drainer.GetStatus() by locking the existing mutex before returning the status snapshot.
  • Replace the shutdown test’s timing-based coordination with testing/synctest to deterministically wait for shutdown blocking.
  • Add a concurrent status polling test intended to catch races between operation updates and status reads.
File summaries
File Description
server/events/drainer.go Locks around GetStatus() to prevent concurrent reads of status racing with updates.
server/events/drainer_test.go Updates shutdown test to use synctest; adds concurrent status polling coverage (currently has a compile issue).
Review details

Suppressed comments (1)

server/events/drainer_test.go:92

  • sync.WaitGroup does not have a Go method; this goroutine should be started with go + wg.Add/Done, otherwise the test won't compile.
	wg.Go(func() {
		<-start
		for range 1000 {
			status := d.GetStatus()
			if status.ShuttingDown || status.InProgressOps < 0 || status.InProgressOps > workers {
  • Files reviewed: 2/2 changed files
  • Comments generated: 1
  • Review effort level: Lite

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread server/events/drainer_test.go
@github-code-quality

github-code-quality Bot commented Sep 7, 2026

Copy link
Copy Markdown

Code Coverage Overview

Languages: Go

Go / code-coverage/go

The overall line coverage in commit b302208 in the fix/drainer-status-r... branch is 73%. Line coverage data for the main branch is not yet available.

Show a line coverage summary of the most covered files.
File main fix/drainer-status-r... b302208 +/-
server/events/v...ithub/client.go 88%
server/core/ter...aform_client.go 88%
server/controll...i_controller.go 83%
server/events/p...mand_builder.go 83%
server/events/v...itlab/client.go 80%
server/events/p...mmand_runner.go 76%
server/events/event_parser.go 76%
server/events/working_dir.go 73%
server/server.go 70%
server/controll...s_controller.go 64%

Updated September 07, 2026 23:47 UTC

@chenrui333
chenrui333 force-pushed the fix/drainer-status-race branch from 7796857 to b1328ca Compare September 7, 2026 07:30
@github-actions github-actions Bot added the go Pull requests that update Go code label Sep 7, 2026
@chenrui333
chenrui333 force-pushed the fix/drainer-status-race branch from b1328ca to 438d1e5 Compare September 7, 2026 09:16
Protect status snapshots with the existing mutex and cover concurrent status polling. Synchronize shutdown tests with the standard-library test scheduler.

Assisted-by: OpenAI
Signed-off-by: Rui Chen <rui@chenrui.dev>
@chenrui333
chenrui333 force-pushed the fix/drainer-status-race branch from 438d1e5 to b302208 Compare September 7, 2026 23:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

go Pull requests that update Go code size/s

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants