Skip to content

fix(batchrouter): do not abort warehouse jobs on a zero failure timestamp - #7426

Merged
achettyiitr merged 2 commits into
masterfrom
fix/batchrouter-warehouse-abort-guard
Sep 29, 2026
Merged

achettyiitr merged 2 commits into
masterfrom
fix/batchrouter-warehouse-abort-guard

Conversation

@achettyiitr

@achettyiitr achettyiitr commented Sep 24, 2026 •

Copy link
Copy Markdown
Member

Linear: INT-7231

Problem

warehouseServiceFailedTime gates whether jobs waiting on a failing warehouse service are retried or aborted with 410. It is meant to give them BatchRouter.warehouseServiceMaxRetryTime (default 3h) before giving up. In practice it can abort them on their first attempt.

Three things combine (router/batchrouter/handle.go):

  1. The field is shared. Factory.New(destType) creates one Handle per destType, so a single warehouseServiceFailedTime describes "is the warehouse service failing" for every destination of that destType in the process.
  2. Any success zeroes it. The else if isWarehouse arm resets it to time.Time{} on every warehouse batch that is not a ping failure — including all the successful ones.
  3. The check re-read the shared field after setting it, rather than using the value it had just written. updateJobStatus runs under BatchRouter.Limiter.upload.limit (default 200) concurrent goroutines on the same Handle, so a concurrent success can zero the field between the write and the read.

time.Since(time.Time{}) is roughly 2,025 years, which exceeds any retry window, so the guard aborts unconditionally when it reads a zero.

Production impact

entusmtprod / enterprise-rudder, 2026-09-23. A workspace migration edited Warehouse.degradedWorkspaceIDs three times in 40 minutes. That key is read with the non-reloadable getter and the operator sets shutdownOnNonReloadableConfigChange: true, so the shared warehouse service restarted three times.

pingWarehouse POSTs to /v1/process failed during the restarts:

dial tcp 172.20.230.47:80: connect: connection refused
context deadline exceeded (Client.Timeout exceeded while awaiting headers)
  • 173 destinations across 108 workspaces, 210,301 events, got 500, retried, and delivered once the service returned — the whole cycle took about two minutes.
  • 4 destinations lost 1,499 events to terminal 410 aborts. The sampled reporting row shows firstAttemptedAt 2026-09-23T20:02:37.175Z, and the abort counter reads its final value by 20:03:00Z — aborted 23 seconds after the job's first attempt, on attempt one.

Neither retry policy can produce that. retryLimitReached needs AttemptNum >= 128 and time.Since(firstAttemptedAt) > retryTimeWindow (24h on this cluster), and it is gated on !notifyWarehouseErr so it was never evaluated. The warehouse branch needs 3 hours. The only way to get 23 seconds is a comparison against the zero time.

During the failing two-minute window generate_staging_files shows ~2,576 batch completions in entusmtprod — roughly 20 calls per second into this code path, most of them successes zeroing the field.

Change

Capture the failure start under the same lock that sets it, and check that local copy:

var warehouseServiceFailedSince time.Time
if isWarehouse && notifyWarehouseErr {
    brt.warehouseServiceFailedTimeMu.Lock()
    if brt.warehouseServiceFailedTime.IsZero() {
        brt.warehouseServiceFailedTime = time.Now()
    }
    warehouseServiceFailedSince = brt.warehouseServiceFailedTime
    brt.warehouseServiceFailedTimeMu.Unlock()
}

and move the decision into a named method that refuses to abort on a zero:

func (brt *Handle) warehouseServiceRetryLimitReached(failedSince time.Time) bool {
	if failedSince.IsZero() {
		return false
	}
	return time.Since(failedSince) > brt.warehouseServiceMaxRetryTime.Load()
}

The zero check is deliberately belt-and-braces: with the capture in place the guard should never see a zero, but if it ever does the safe direction is to retry, not to discard customer data.

Verification

go test ./router/batchrouter/ -run TestWarehouseServiceRetryLimitReached -race -count=1
ok  github.com/rudderlabs/rudder-server/router/batchrouter

The test fails without the fix — removing the IsZero guard produces:

--- FAIL: TestWarehouseServiceRetryLimitReached/zero_failedSince_never_aborts
    Should be false
    a zero failure start must not abort: it is year 1 and exceeds every retry window

go build ./router/... and go vet ./router/batchrouter/ are clean.

There were no existing tests for warehouseServiceFailedTime, warehouseServiceMaxRetryTime or updateJobStatus, which is how this survived since #3248 (May 2023).

Deliberately not in this PR

The field is still shared across every destination of a destType, so one destination's success still clears the failure clock for the others. That means the 3-hour window can struggle to accumulate on a busy shared namespace and the guard will under-abort. That is the safe direction, and fixing it properly means keying the state by destination — a larger change worth doing separately.

Not proven

The exact interleaving for those four destinations is deduced, not observed: nothing logs or counts the reset. It is the only remaining mechanism after ruling out retryLimitReached (arithmetically impossible at 23s), a configuration override (no override in the operator or devops repos), the drainer path (emits drained_events, which is absent for these destinations), and degradedWorkspaceIDs (only filters config; the degraded workspace itself had zero aborts, and none of the four was ever on the list).

🤖 Generated with Claude Code

https://claude.ai/code/session_012YX6Cdjs6iKeJCtzm9udju

achettyiitr and others added 2 commits September 24, 2026 17:58
…tamp

warehouseServiceFailedTime is a single field on the Handle, shared by every
destination of a destType, and the `else if isWarehouse` arm zeroes it on any
warehouse batch that is not a ping failure - including every successful one.
The abort check re-read that field after setting it, so a concurrent success
could zero it in between. time.Since(time.Time{}) is ~2000 years, which
exceeds any retry window, so the job was aborted with 410 on its first attempt
instead of being retried.

Capture the failure start under the same lock that sets it and check the local
copy, and never abort on a zero timestamp.

Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_012YX6Cdjs6iKeJCtzm9udju
There were no tests for warehouseServiceFailedTime, warehouseServiceMaxRetryTime
or updateJobStatus, which is how the zero-timestamp abort survived since #3248.

Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_012YX6Cdjs6iKeJCtzm9udju
@codecov

codecov Bot commented Sep 24, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 84.96%. Comparing base (a3e2a3c) to head (c503983).
⚠️ Report is 1 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #7426      +/-   ##
==========================================
+ Coverage   84.49%   84.96%   +0.46%     
==========================================
  Files         622      622              
  Lines       62045    62048       +3     
==========================================
+ Hits        52427    52720     +293     
+ Misses       9615     9325     -290     
  Partials        3        3              

☔ 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.

@achettyiitr
achettyiitr merged commit 52d2b55 into master Sep 29, 2026
74 checks passed
@achettyiitr
achettyiitr deleted the fix/batchrouter-warehouse-abort-guard branch September 29, 2026 04:23
itsmihir added a commit that referenced this pull request Sep 29, 2026
# Description

Syncing release v1.89.0 to main branch

**WARNING: Do NOT rewrite git history and ALWAYS use a "Merge Commit"
for merging!**

**↓↓ Please review and edit commit overrides before merging ↓↓**

BEGIN_COMMIT_OVERRIDE
fix(batchrouter): do not abort warehouse jobs on a zero failure
timestamp (#7426)
END_COMMIT_OVERRIDE
This was referenced Oct 12, 2026
mihir20 pushed a commit that referenced this pull request Oct 12, 2026
🤖 I have created a release *beep* *boop*
---


##
[1.90.0-rc.1](v1.89.0...v1.90.0-rc.1)
(2026-10-12)


### Features

* **processor:** add source_out reporting metric
([#7435](#7435))
([909fba9](909fba9))
* **processor:** allow disabling event schemas v2 per source
([#7429](#7429))
([a8c12b2](a8c12b2))
* **processor:** report dest_transformer diff rows for multiplexing
destination transformations
([#7446](#7446))
([cd95c32](cd95c32))
* **processor:** report dest_transformer succeeded for destinations
without a destination transformation
([#7445](#7445))
([21f7e41](21f7e41))
* **processor:** report user_transformer succeeded for destinations
without a user transformation
([#7440](#7440))
([f424257](f424257))
* **router:** mask live events destination credentials
([#7460](#7460))
([5fa5fe2](5fa5fe2))
* **warehouse:** add Microsoft Fabric destination
([#7441](#7441))
([74940c2](74940c2))


### Bug Fixes

* **batchrouter:** do not abort warehouse jobs on a zero failure
timestamp
([#7426](#7426))
([506f6d5](506f6d5))
* **batchrouter:** recover snowpipe streaming channels for tables
dropped externally
([#7434](#7434))
([93cd81d](93cd81d))
* **destination:** encode Lytics bulk upload URL values
([#7433](#7433))
([08e6937](08e6937))
* **destination:** retry bqstream transport failures
([#7464](#7464))
([cd3dc3e](cd3dc3e))
* **warehouse:** cap deltalake validation schema describes
([#7444](#7444))
([d119779](d119779))
* **warehouse:** keep snowflake copy credentials out of logs
([#7442](#7442))
([f91747b](f91747b))
* **warehouse:** set explicit lineSep for deltalake csv copy
([#7455](#7455))
([cc22d18](cc22d18))


### Miscellaneous

* migrate self-hosted arm64 docker build runners to gha-runner-scale-set
([#7425](#7425))
([5cdffde](5cdffde))
* **processor:** retire the destination-filter reorder, dedup and
gw_ingested reporting flags
([#7450](#7450))
([1040511](1040511))
* pull openapi-generator through the ECR pull-through cache
([#7449](#7449))
([6e9f920](6e9f920))

---
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>
mihir20 pushed a commit that referenced this pull request Oct 13, 2026
🤖 I have created a release *beep* *boop*
---


##
[1.90.0](v1.89.0...v1.90.0)
(2026-10-12)


### Features

* **processor:** add source_out reporting metric
([#7435](#7435))
([909fba9](909fba9))
* **processor:** allow disabling event schemas v2 per source
([#7429](#7429))
([a8c12b2](a8c12b2))
* **processor:** report dest_transformer diff rows for multiplexing
destination transformations
([#7446](#7446))
([cd95c32](cd95c32))
* **processor:** report dest_transformer succeeded for destinations
without a destination transformation
([#7445](#7445))
([21f7e41](21f7e41))
* **processor:** report user_transformer succeeded for destinations
without a user transformation
([#7440](#7440))
([f424257](f424257))
* **router:** mask live events destination credentials
([#7460](#7460))
([5fa5fe2](5fa5fe2))
* **warehouse:** add Microsoft Fabric destination
([#7441](#7441))
([74940c2](74940c2))


### Bug Fixes

* **batchrouter:** do not abort warehouse jobs on a zero failure
timestamp
([#7426](#7426))
([506f6d5](506f6d5))
* **batchrouter:** recover snowpipe streaming channels for tables
dropped externally
([#7434](#7434))
([93cd81d](93cd81d))
* **destination:** encode Lytics bulk upload URL values
([#7433](#7433))
([08e6937](08e6937))
* **destination:** retry bqstream transport failures
([#7464](#7464))
([cd3dc3e](cd3dc3e))
* **warehouse:** cap deltalake validation schema describes
([#7444](#7444))
([d119779](d119779))
* **warehouse:** keep snowflake copy credentials out of logs
([#7442](#7442))
([f91747b](f91747b))
* **warehouse:** set explicit lineSep for deltalake csv copy
([#7455](#7455))
([cc22d18](cc22d18))


### Miscellaneous

* migrate self-hosted arm64 docker build runners to gha-runner-scale-set
([#7425](#7425))
([5cdffde](5cdffde))
* **processor:** retire the destination-filter reorder, dedup and
gw_ingested reporting flags
([#7450](#7450))
([1040511](1040511))
* pull openapi-generator through the ECR pull-through cache
([#7449](#7449))
([6e9f920](6e9f920))

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

2 participants