Skip to content

fix: race conditions while counting initial pending events can cause wrong counting - #7292

Merged
atzoum merged 1 commit into
masterfrom
fix.pendingEventsRace
Aug 25, 2026
Merged

atzoum merged 1 commit into
masterfrom
fix.pendingEventsRace

Conversation

@atzoum

@atzoum atzoum commented Aug 19, 2026 •

Copy link
Copy Markdown
Contributor

Description

Pending event counts can drift at startup, since the pileup count and the live counters don't agree on a single boundary:

  • Jobs stored by the processor while the count is running are counted twice: the cutoff is applied to statuses (exec_time) but not to jobs, so the query counts them, and so does the jobsdb wrapper's increase.
  • The registry is reset after the cutoff is captured and once more on every retry attempt, discarding whatever the running processor has registered in the meantime.
  • Pausing compaction is advisory - it only keeps new rounds from starting - so a compaction already in flight keeps moving datasets while the count queries them.

Key changes:

  • The cutoff and the registry reset move ahead of the processor's loops. The processor is the only writer of rt/batch_rt jobs and always starts before router & batch router, so nothing can be written below the cutoff once it is captured, and everything above it is accounted for by the pending events jobsdb wrappers.
  • GetPileUpCounts applies the cutoff to both sides, created_at for jobs and exec_time for statuses.
  • Retries no longer reset the registry: counts are accumulated per attempt and applied only after every query has succeeded.
  • The compaction pause becomes a lock - taken exclusively by compaction, which skips the round if it can't get it, and for reading by the count, which waits for an in-flight compaction and keeps the next ones out.

Linear Ticket

resolves 3299

Security

  • The code changed/added as part of this pull request won't create any security issues with how the software is being used.

@codecov

codecov Bot commented Aug 19, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 97.61905% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 80.15%. Comparing base (7a83281) to head (51fd481).

Files with missing lines Patch % Lines
processor/manager.go 66.66% 0 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #7292      +/-   ##
==========================================
+ Coverage   79.73%   80.15%   +0.41%     
==========================================
  Files         601      601              
  Lines       67308    67336      +28     
==========================================
+ Hits        53671    53972     +301     
+ Misses      10464    10183     -281     
- Partials     3173     3181       +8     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@atzoum
atzoum force-pushed the fix.pendingEventsRace branch from 645957d to 2d34aa3 Compare August 19, 2026 13:58
@atzoum
atzoum force-pushed the fix.pendingEventsRace branch from 2d34aa3 to 7e59d0f Compare August 24, 2026 08:18
@ktgowtham

Copy link
Copy Markdown
Contributor

@mihir20 could you review this one

@atzoum
atzoum force-pushed the fix.pendingEventsRace branch from 7e59d0f to 51fd481 Compare August 24, 2026 14:08

@mihir20 mihir20 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.

LGTM

@atzoum
atzoum merged commit 3efa718 into master Aug 25, 2026
76 checks passed
@atzoum
atzoum deleted the fix.pendingEventsRace branch August 25, 2026 08:16
mihir20 pushed a commit that referenced this pull request Aug 31, 2026
…wrong counting (#7292)

# Description

Pending event counts can drift at startup, since the pileup count and
the live counters don't agree on a single boundary:

- Jobs stored by the processor while the count is running are counted
twice: the cutoff is applied to statuses (`exec_time`) but not to jobs,
so the query counts them, and so does the jobsdb wrapper's increase.
- The registry is reset after the cutoff is captured and once more on
every retry attempt, discarding whatever the running processor has
registered in the meantime.
- Pausing compaction is advisory - it only keeps new rounds from
starting - so a compaction already in flight keeps moving datasets while
the count queries them.

Key changes:

- The cutoff and the registry reset move ahead of the processor's loops.
The processor is the only writer of rt/batch_rt jobs and always starts
before router & batch router, so nothing can be written below the cutoff
once it is captured, and everything above it is accounted for by the
pending events jobsdb wrappers.
- `GetPileUpCounts` applies the cutoff to both sides, `created_at` for
jobs and `exec_time` for statuses.
- Retries no longer reset the registry: counts are accumulated per
attempt and applied only after every query has succeeded.
- The compaction pause becomes a lock - taken exclusively by compaction,
which skips the round if it can't get it, and for reading by the count,
which waits for an in-flight compaction and keeps the next ones out.

## Linear Ticket

resolves 3299

## Security

- [x] The code changed/added as part of this pull request won't create
any security issues with how the software is being used.
This was referenced Aug 31, 2026
itsmihir pushed a commit that referenced this pull request Aug 31, 2026
🤖 I have created a release *beep* *boop*
---


##
[1.85.0-rc.1](v1.84.0...v1.85.0-rc.1)
(2026-08-31)


### Features

* backend config v2 resolver with stub mapper
([#7275](#7275))
([267b973](267b973))
* **warehouse:** clickhouse v2 connection and schema
([#7301](#7301))
([2eb1fa6](2eb1fa6))
* **warehouse:** clickhouse v2 ddl operations
([#7302](#7302))
([f2887c5](f2887c5))
* **warehouse:** clickhouse v2 loading
([#7303](#7303))
([3e48618](3e48618))
* **warehouse:** enable the clickhouse v2 driver behind a flag
([#7311](#7311))
([3ce1da5](3ce1da5))


### Bug Fixes

* race conditions while counting initial pending events can cause wrong
counting
([#7292](#7292))
([3efa718](3efa718))
* replay destinations not using the config corresponding to their
connected source type
([#7307](#7307))
([ee7aa93](ee7aa93))
* **router:** abort router-transform on proactive invalid_grant instead
of retrying (INT-6779)
([#7175](#7175))
([4d7348d](4d7348d))
* tracking plan merged config is cached without its event type
([#7314](#7314))
([624dd5c](624dd5c))


### Miscellaneous

* setattr/delattr hardening
([#7291](#7291))
([2855af4](2855af4))
* sync release v1.84.0 to main branch
([#7306](#7306))
([fa102b7](fa102b7))
* webhook reasons
([#7294](#7294))
([c298d59](c298d59))

---
This PR was generated with [Release
Please](https://github.com/googleapis/release-please). See
[documentation](https://github.com/googleapis/release-please#release-please).

Co-authored-by: rudderstack-github-actions[bot] <236995729+rudderstack-github-actions[bot]@users.noreply.github.com>
itsmihir pushed a commit that referenced this pull request Sep 1, 2026
🤖 I have created a release *beep* *boop*
---


##
[1.85.0](v1.84.0...v1.85.0)
(2026-08-31)


### Features

* backend config v2 resolver with stub mapper
([#7275](#7275))
([267b973](267b973))
* **warehouse:** clickhouse v2 connection and schema
([#7301](#7301))
([2eb1fa6](2eb1fa6))
* **warehouse:** clickhouse v2 ddl operations
([#7302](#7302))
([f2887c5](f2887c5))
* **warehouse:** clickhouse v2 loading
([#7303](#7303))
([3e48618](3e48618))
* **warehouse:** enable the clickhouse v2 driver behind a flag
([#7311](#7311))
([3ce1da5](3ce1da5))


### Bug Fixes

* race conditions while counting initial pending events can cause wrong
counting
([#7292](#7292))
([3efa718](3efa718))
* replay destinations not using the config corresponding to their
connected source type
([#7307](#7307))
([ee7aa93](ee7aa93))
* **router:** abort router-transform on proactive invalid_grant instead
of retrying (INT-6779)
([#7175](#7175))
([4d7348d](4d7348d))
* tracking plan merged config is cached without its event type
([#7314](#7314))
([624dd5c](624dd5c))


### Miscellaneous

* setattr/delattr hardening
([#7291](#7291))
([2855af4](2855af4))
* sync release v1.84.0 to main branch
([#7306](#7306))
([fa102b7](fa102b7))
* webhook reasons
([#7294](#7294))
([c298d59](c298d59))

---
This PR was generated with [Release
Please](https://github.com/googleapis/release-please). See
[documentation](https://github.com/googleapis/release-please#release-please).

Co-authored-by: rudderstack-github-actions[bot] <236995729+rudderstack-github-actions[bot]@users.noreply.github.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.

3 participants