Skip to content

fix(core): schema forwarder panics on shutdown - #7519

Merged
atzoum merged 8 commits into
masterfrom
fix/schema-forwarder-shutdown-race
Nov 2, 2026
Merged

atzoum merged 8 commits into
masterfrom
fix/schema-forwarder-shutdown-race

Conversation

@atzoum

@atzoum atzoum commented Oct 21, 2026 •

Copy link
Copy Markdown
Contributor

Description

Pulsar's Flush could return before every SendMessageAsync callback has run, so late callbacks ended up mutating messageBatches and statuses while the forwarder goroutine was reading them and the abort loop could dereference a nil slot left by slices.Delete.
Callbacks now only send their outcome to a buffered, per-attempt channel, which the forwarder goroutine drains after Flush with lo.BufferWithContext, bounded by the new SchemaForwarder.callbackTimeout (default 30s, pulsar's default SendTimeout) and shutdown. Batches without an outcome are retried and eventually aborted, which also covers messages pulsar never calls back for when it closes the producer.

Linear Ticket

N/A

Security

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

🤖 Generated with Claude Code

@codecov

codecov Bot commented Oct 21, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 84.78%. Comparing base (902160f) to head (c4f67de).
⚠️ Report is 3 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #7519      +/-   ##
==========================================
+ Coverage   84.70%   84.78%   +0.07%     
==========================================
  Files         631      631              
  Lines       62941    62959      +18     
==========================================
+ Hits        53317    53377      +60     
+ Misses       9621     9579      -42     
  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.

@atzoum
atzoum force-pushed the fix/schema-forwarder-shutdown-race branch 14 times, most recently from 39def60 to e0e426b Compare October 27, 2026 10:03
Copilot AI balanced review requested due to automatic review settings October 27, 2026 10:03

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Regression coverage is still needed for shutdown during callback collection and callbacks arriving after collection stops.

1 open issue
What changed in this PR

This PR addresses schema-forwarder shutdown panics by keeping batch and job-status updates in the forwarder goroutine rather than producer callbacks.

Changes:

  • Collect callback outcomes through buffered, per-attempt channels.
  • Bound callback collection by a configurable timeout and shutdown cancellation.
  • Add tests for delayed callbacks after failed flushes and callbacks that never arrive.
File Description
schema-forwarder/​internal/​forwarder/​jobsforwarder.go Serializes callback-result processing and bounds the collection wait.
schema-forwarder/​internal/​forwarder/​jobsforwarder_test.go Adds controllable producers and delayed/missing-callback regression tests.

Review effort: Balanced

return nil //nolint:nilerr
}
toForward := append([]*batcher.EventSchemaMessageBatch{}, messageBatches...)
resultsCh := make(chan lo.Tuple2[*batcher.EventSchemaMessageBatch, error], len(toForward)) // buffered so that callbacks never block, even after the attempt stops reading

@fracasula fracasula Oct 27, 2026 •

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Late acks land in this per-attempt channel after we've stopped reading it, so the batch gets resent even though it was delivered. Rare, and fine with at-least-once, but event-schema counts every copy. Maybe wait at least pulsar's SendTimeout (30s)? Not blocking.

@atzoum atzoum Oct 27, 2026 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Raising the default to 30s (7c2ae75). It only matters when Flush returns early (a partition fails, or the producer is closing): otherwise all outcomes are already buffered when Flush returns, and on Stop the wait ends with the context.


// Flush can return before all callbacks have run, and pulsar never calls back for messages
// still batched when it closes the producer
waitCtx, cancel := context.WithTimeout(ctx, jf.callbackTimeout.Load())

@fracasula fracasula Oct 27, 2026 •

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On Stop this ctx is already done, and BufferWithContext picks randomly between ready results and Done(), so delivered jobs end up counted as aborted (metric only). An if ctx.Err() != nil { return nil } right after backoffvoid.Retry would fix it.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Returning early on ctx.Err() in the Retry error branch (e80403e), which also covers a Stop during the backoff sleep. The Stop-during-wait test asserts nothing is counted as aborted.

jf.initialRetryInterval = config.GetReloadableDurationVar(10, time.Second, "SchemaForwarder.initialRetryInterval")
jf.maxRetryInterval = config.GetReloadableDurationVar(60, time.Second, "SchemaForwarder.maxRetryInterval")
jf.maxRetryElapsedTime = config.GetReloadableDurationVar(60, time.Minute, "SchemaForwarder.maxRetryElapsedTime")
jf.callbackTimeout = config.GetReloadableDurationVar(10, time.Second, "SchemaForwarder.callbackTimeout")

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: if someone sets this to 0 or less to turn the wait off, the same random select reads about one result per attempt, so acked batches get resent or aborted. Maybe fall back to the default when it's <= 0?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not guarding this one: there's no meaningful "off" value since the wait is what covers an early Flush return, and the other durations here aren't guarded either.

// still batched when it closes the producer
waitCtx, cancel := context.WithTimeout(ctx, jf.callbackTimeout.Load())
defer cancel()
results, _, _, _ := lo.BufferWithContext(waitCtx, resultsCh, len(toForward))

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: when we give up with outcomes still missing, nothing is logged, and backoff doesn't log either, so it stays invisible until the abort an hour later. A Warnn here when len(results) < len(toForward), with the missing count, flushErr and the timeout, would help.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Logging each retry from backoff's notify hook instead (8272cf5), so flush errors are covered too and Stop doesn't log. The error now carries the missing count and the timeout, and the final abort is logged as well.

require.Len(t, seen, numOfJobs, "every job should have a status")
})

t.Run("jobs whose producer callbacks never arrive are aborted", func(t *testing.T) {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: these two don't use the pulsar/postgres containers from the parent test, so they could be top-level tests and run without Docker.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I deliberately added them as nested tests so that they can all run under a single parent. Even though thry don't need docker, running in this context doesn't hurt anyone

@atzoum
atzoum force-pushed the fix/schema-forwarder-shutdown-race branch from e0e426b to b879ffc Compare October 27, 2026 17:02
Copilot AI balanced review requested due to automatic review settings October 27, 2026 17:30

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔵 Needs a closer look

The concurrency-sensitive shutdown changes warrant human confirmation with race-enabled regression tests, which were not run during this review.

No open issues 🎉

Review effort: Balanced

Copilot AI balanced review requested due to automatic review settings October 27, 2026 18:48

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

The changes isolate callback state mutations and cover the principal failure and shutdown paths, with no unresolved review findings.

No open issues 🎉

Review effort: Balanced

Copilot AI balanced review requested due to automatic review settings October 27, 2026 18:56

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔵 Needs a closer look

Shutdown behavior under asynchronous Pulsar callback timing still warrants human review and runtime validation.

No open issues 🎉

Review effort: Balanced

Pulsar's Flush can return before every SendMessageAsync callback has run
(e.g. when flushing one partition fails). Late callbacks then removed
batches from messageBatches and appended to statuses while the forwarder
goroutine read both without the lock, so the abort loop could hit a nil
slot left behind by slices.Delete.

Each forward attempt now sets a mu-guarded flushDone flag once Flush
returns, and callbacks arriving after it are ignored, so the forwarder
goroutine reads messageBatches and statuses without racing them. An
ignored success leaves its batch to be resent or aborted.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

🔒 Scanned for secrets using gitleaks 8.30.1
Co-Authored-By: Claude Opus 5.5 <[email protected]>

🔒 Scanned for secrets using gitleaks 8.30.1
…wait

Co-Authored-By: Claude Opus 5.5 <[email protected]>

🔒 Scanned for secrets using gitleaks 8.30.1
Co-Authored-By: Claude Opus 5.5 <[email protected]>

🔒 Scanned for secrets using gitleaks 8.30.1
Co-Authored-By: Claude Opus 5.5 <[email protected]>

🔒 Scanned for secrets using gitleaks 8.30.1
… varies

Co-Authored-By: Claude Opus 5.5 <[email protected]>

🔒 Scanned for secrets using gitleaks 8.30.1
… successful

Co-Authored-By: Claude Opus 5.5 <[email protected]>

🔒 Scanned for secrets using gitleaks 8.30.1
Co-Authored-By: Claude Opus 5.5 <[email protected]>

🔒 Scanned for secrets using gitleaks 8.30.1
@atzoum
atzoum force-pushed the fix/schema-forwarder-shutdown-race branch from 2b884a5 to c4f67de Compare October 30, 2026 10:43
Copilot AI balanced review requested due to automatic review settings October 30, 2026 10:43

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota.

@atzoum
atzoum merged commit dd61cfc into master Nov 2, 2026
74 of 75 checks passed
@atzoum
atzoum deleted the fix/schema-forwarder-shutdown-race branch November 2, 2026 07:25
atzoum pushed a commit that referenced this pull request Nov 9, 2026
🤖 I have created a release *beep* *boop*
---


##
[1.93.0-rc.1](v1.92.0...v1.93.0-rc.1)
(2026-11-09)


### Features

* **destination:** recognize machine_oauth accounts as oauth
([#7549](#7549))
([f51e4ca](f51e4ca))
* incremental definitions on the v2 namespace config
([#7487](#7487))
([ce51e38](ce51e38))
* **processor:** add flag to abort python transformations on deployments
that do not offer them
([#7571](#7571))
([ca85eb2](ca85eb2))
* **processor:** filter http v2 events by destination message types
([#7538](#7538))
([58fd176](58fd176))
* **processor:** send the workspace id to per-workspace pyt pods
([#7551](#7551))
([ea33835](ea33835))
* **warehouse:** add maxcompute destination
([#7568](#7568))
([a64bfd9](a64bfd9))


### Bug Fixes

* **batchrouter:** abort bq stream all events jobs on terminal auth
failures
([#7548](#7548))
([6b7e023](6b7e023))
* bump andybalholm/brotli to v1.2.7 [SEC-759]
([#7525](#7525))
([6dfe468](6dfe468))
* bump rudder-go-kit to v0.84.3
([#7547](#7547))
([355054a](355054a))
* **core:** schema forwarder panics on shutdown
([#7519](#7519))
([dd61cfc](dd61cfc))
* database connections hang when context is cancelled during a copy
([#7578](#7578))
([8dae6e3](8dae6e3))
* **jobsdb:** compaction missing pairs after one that doesn't fit
([#7574](#7574))
([573271b](573271b))
* **jobsdb:** multiconsumer recovery misses a consumer's executing
status after another consumer's later status
([#7554](#7554))
([69b43e0](69b43e0))
* **jobsdb:** old jobs not expiring for every consumer
([#7573](#7573))
([366f114](366f114))
* **jobsdb:** pickups stalling on status tables with skewed stats
([#7572](#7572))
([318446f](318446f))
* **jobsdb:** unionjobsdb functions pick the first datasets by table
name ([#7558](#7558))
([e94d6c5](e94d6c5))
* **router:** event order test only counts drained jobs of the last
dataset
([#7552](#7552))
([b0a097a](b0a097a))
* **router:** mask secrets in array-shaped reporting samples
([#7536](#7536))
([902160f](902160f))
* **warehouse:** hot-reload degraded workspaces without aborting
restored uploads
([#7564](#7564))
([cb98598](cb98598))
* **warehouse:** match deltalake columns case-insensitively
([#7563](#7563))
([a7d30d7](a7d30d7))
* **warehouse:** migrate snowflake to gosnowflake v2.3.0
([#7542](#7542))
([cc09426](cc09426))
* **warehouse:** skip job-creation error log on router shutdown
([#7567](#7567))
([895367e](895367e))


### Miscellaneous

* **deps:** bump github.com/go-jose/go-jose/v4 from 4.1.4 to 4.1.6
([#7545](#7545))
([35ee952](35ee952))
* export only the +Inf bucket for limiter timers
([#7570](#7570))
([4429472](4429472))
* **router:** add drainReason label to pipeline_processed_events
([#7561](#7561))
([af0aef8](af0aef8))
* sync release v1.92.0 to main branch
([#7534](#7534))
([9ab165d](9ab165d))
* **warehouse:** bump sqlconnect-go to v1.37.1
([#7575](#7575))
([acdad67](acdad67))

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


##
[1.93.0](v1.92.0...v1.93.0)
(2026-11-09)


### Features

* **destination:** recognize machine_oauth accounts as oauth
([#7549](#7549))
([f51e4ca](f51e4ca))
* incremental definitions on the v2 namespace config
([#7487](#7487))
([ce51e38](ce51e38))
* **processor:** add flag to abort python transformations on deployments
that do not offer them
([#7571](#7571))
([ca85eb2](ca85eb2))
* **processor:** filter http v2 events by destination message types
([#7538](#7538))
([58fd176](58fd176))
* **processor:** send the workspace id to per-workspace pyt pods
([#7551](#7551))
([ea33835](ea33835))
* **warehouse:** add maxcompute destination
([#7568](#7568))
([a64bfd9](a64bfd9))


### Bug Fixes

* **batchrouter:** abort bq stream all events jobs on terminal auth
failures
([#7548](#7548))
([6b7e023](6b7e023))
* bump andybalholm/brotli to v1.2.7 [SEC-759]
([#7525](#7525))
([6dfe468](6dfe468))
* bump rudder-go-kit to v0.84.3
([#7547](#7547))
([355054a](355054a))
* **core:** schema forwarder panics on shutdown
([#7519](#7519))
([dd61cfc](dd61cfc))
* database connections hang when context is cancelled during a copy
([#7578](#7578))
([8dae6e3](8dae6e3))
* **jobsdb:** compaction missing pairs after one that doesn't fit
([#7574](#7574))
([573271b](573271b))
* **jobsdb:** multiconsumer recovery misses a consumer's executing
status after another consumer's later status
([#7554](#7554))
([69b43e0](69b43e0))
* **jobsdb:** old jobs not expiring for every consumer
([#7573](#7573))
([366f114](366f114))
* **jobsdb:** pickups stalling on status tables with skewed stats
([#7572](#7572))
([318446f](318446f))
* **jobsdb:** unionjobsdb functions pick the first datasets by table
name ([#7558](#7558))
([e94d6c5](e94d6c5))
* **router:** event order test only counts drained jobs of the last
dataset
([#7552](#7552))
([b0a097a](b0a097a))
* **router:** mask secrets in array-shaped reporting samples
([#7536](#7536))
([902160f](902160f))
* **warehouse:** hot-reload degraded workspaces without aborting
restored uploads
([#7564](#7564))
([cb98598](cb98598))
* **warehouse:** match deltalake columns case-insensitively
([#7563](#7563))
([a7d30d7](a7d30d7))
* **warehouse:** migrate snowflake to gosnowflake v2.3.0
([#7542](#7542))
([cc09426](cc09426))
* **warehouse:** skip job-creation error log on router shutdown
([#7567](#7567))
([895367e](895367e))


### Miscellaneous

* **deps:** bump github.com/go-jose/go-jose/v4 from 4.1.4 to 4.1.6
([#7545](#7545))
([35ee952](35ee952))
* export only the +Inf bucket for limiter timers
([#7570](#7570))
([4429472](4429472))
* **router:** add drainReason label to pipeline_processed_events
([#7561](#7561))
([af0aef8](af0aef8))
* sync release v1.92.0 to main branch
([#7534](#7534))
([9ab165d](9ab165d))
* **warehouse:** bump sqlconnect-go to v1.37.1
([#7575](#7575))
([acdad67](acdad67))

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

4 participants