Skip to content

NormalizeLoop: fix normalize race#4168

Merged
Amogh-Bharadwaj merged 1 commit into
mainfrom
pg-pg/fix-normalize-halt
Apr 13, 2026
Merged

NormalizeLoop: fix normalize race#4168
Amogh-Bharadwaj merged 1 commit into
mainfrom
pg-pg/fix-normalize-halt

Conversation

@Amogh-Bharadwaj

@Amogh-Bharadwaj Amogh-Bharadwaj commented Apr 13, 2026

Copy link
Copy Markdown
Contributor

There's a race condition in normalizeLoop with the LastChan signaling mechanism.

The race:

  • normalizeLoop is inside startNormalize processing batch 346
  • Sync thread completes batch 347 and calls normRequests.Update(347) — this stores value 347, creates a new channel, and closes the old channel
  • startNormalize for 346 returns, normalizeLoop goes back to the top
  • normalizeRequests.Wait() returns the new (unclosed) channel created in step 2
  • normalizeLoop blocks on <-ch — but this channel will only be closed by the next Update() (batch 348)
  • So the signal for batch 347 is missed. Normalize 347 won't start until batch 348 is synced (which may never happen if traffic is low)

Check for pending work via Load() before calling Wait(). Only block on the channel if there's genuinely nothing to process.

@Amogh-Bharadwaj Amogh-Bharadwaj requested a review from serprex April 13, 2026 12:36
@github-actions

Copy link
Copy Markdown
Contributor

🔄 Flaky Test Detected

Analysis: e2e TestGenericBQ failed with "UNEXPECTED TIMEOUT" waiting for inherited table rows to appear in BigQuery, a timing-dependent polling assertion in a slow external-service e2e test.
Confidence: 0.92

✅ Automatically retrying the workflow

View workflow run

@github-actions

Copy link
Copy Markdown
Contributor

🔄 Flaky Test Detected

Analysis: TestApiPg/TestResyncFailed failed during teardown due to a race condition where the replication slot was still held by an active PID when the test tried to drop it — a timing issue unrelated to the test logic itself.
Confidence: 0.92

✅ Automatically retrying the workflow

View workflow run

@Amogh-Bharadwaj Amogh-Bharadwaj merged commit b0735da into main Apr 13, 2026
19 of 21 checks passed
@Amogh-Bharadwaj Amogh-Bharadwaj deleted the pg-pg/fix-normalize-halt branch April 13, 2026 13:55
@Amogh-Bharadwaj Amogh-Bharadwaj changed the title Postgres target normalize: fix normalize race NormalizeLoop: fix normalize race Apr 24, 2026
@ilidemi

ilidemi commented May 4, 2026

Copy link
Copy Markdown
Contributor

LGTM

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.

3 participants