Skip to content

feat(processor): reset the per-workspace pyt client on 421 - #7494

Merged
fracasula merged 11 commits into
masterfrom
feature/pipe-3553-01-rudder-server-reset-the-pyt-client-on-421
Oct 23, 2026
Merged

fracasula merged 11 commits into
masterfrom
feature/pipe-3553-01-rudder-server-reset-the-pyt-client-on-421

Conversation

@fracasula

@fracasula fracasula commented Oct 16, 2026 •

Copy link
Copy Markdown
Collaborator

Description

pyt pods will soon refuse work that isn't theirs with 421 Misdirected Request (PIPE-3552). This PR makes rudder-server recover from a 421 instead of failing the batch. It has to be live everywhere before pyt starts sending 421.

Why: on 2026-10-08, production /customTransform traffic for one workspace reached an ephemeral pyt test pod. That pod had been given the IP the workspace's production pod released about 100s earlier. The workspace was scaled to zero, and httplb keeps its last known addresses when DNS answers empty or fails (balancer.go in v0.4.1), so the stale IP stayed in the client. Today rudder-server treats a 421 like any other 4xx, which is final and fails every event in the batch.

What changes:

  • One pyt client per target:
    • Targets are pyt-<ws>:8080, the ephemeral test-pod hosts and the AST URL, keyed by scheme://host:port.
    • Each client is built on first use from the same UserTransformer client config, and closed after Processor.UserTransformer.pytClientIdleTimeout of idleness (reloadable, default 5m).
    • Clients are reference counted, so neither the idle close nor a reset closes a client under a request. httplb's Close waits for requests already in flight, but fails any that start afterwards.
    • JS keeps the shared client.
  • 421 on the event path (doPost), per-workspace PyT only:
    • The 421 is counted on processor_user_transformer_misdirected_requests_total{workspaceID, language} and logged with X-Rudder-Error-Reason. pyt chooses that header, so it is capped and sanitised the same way as the retry-reason stats tag before it reaches logs and error texts.
    • The target's client is retired, so the retry builds a fresh client that resolves DNS again.
    • Only the first 421 from a given client retires it, so concurrent chunks that hit the same stale pod cause one reset, counted on processor_user_transformer_client_resets_total{workspaceID, reason="misdirected"}.
    • If the workspace is at zero, the fresh lookup fails and the existing cold-start path takes over. The 421 itself never touches the cold-start counter KEDA scales on.
    • A 421 that outlasts doPost's retries returns ErrMisdirected, which becomes 819 like ErrColdStart, so sendBatch keeps retrying instead of panicking.
  • 421 on the forward path (forwardTest, which serves /test, /testRun, /test-library and /extract-libs):
    • Same counters and reset. The misdirected counter also carries path, like the cold-start counter there.
    • Retried within maxRetry and the caller's deadline.
  • Outside per-workspace PyT: a 421 stays a final 4xx, as today. rudder-transformer never sends one.
  • transformerclient.NewClosableClient: new; returns the client together with its close func. NewClient is unchanged for its other callers.
  • sendBatch retry log: now carries the 819 body, so it tells a misdirected request apart from a cold start.

Why reset the whole client instead of dropping one address: httplb has no API to evict a single address. A custom health checker would have to map each response back to its connection, and decide when that IP can be trusted again. A fresh client scoped to one target avoids both and is cheap.

Testing:

  • Setup: the new tests use real httplb clients against httptest pods, with a fake resolver so a failed DNS lookup is deterministic.
  • Covered:
    • one reset per client under concurrent chunks, and only that target's client;
    • JS staying final and on the shared client;
    • a reset through New's real client factory;
    • a failed fresh lookup becoming a cold start, on both paths;
    • a persistent 421 becoming 819, with and without endless retries;
    • forwardTest's reset, retry and deadline;
    • the registry lifecycle: retire once, close after release, idle close, the epoch guard and a concurrency stress run;
    • a slow close never blocking a request, whether it comes from a retire or an idle close;
    • the reason header being sanitised, and a WithClient-injected client never being closed.
  • Checked by breaking them: the main guards. Each was mutated, and a test failed rather than hung.
  • Run locally: go test -race for internal/transformer-client, processor/internal/transformer, processor/internal/transformer/user_transformer and processor/cpservice.
  • Already racy on master: destination_transformer, sourcehydration and trackingplan_validation fail under -race because of races in their own test fixtures, so they ran without it. This PR doesn't touch them.
  • Left to CI: the Docker-backed ./processor package tests.

Not in this PR: setting PYT_MODE=test in the test-pod deployer (PIPE-3554), and DMT's handling of 421 (PIPE-3555).

Linear Ticket

Fixes PIPE-3553

Security

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

pyt pods will refuse work that isn't theirs with 421 Misdirected Request. Today rudder-server treats any 4xx as
final, so a 421 would fail the whole batch; this must be live before pyt starts sending them.

pyt traffic now uses one transformer client per target (pyt-<ws>:8080, test-pod hosts, the AST URL), built on first
use from the UserTransformer client config and closed once idle (Processor.UserTransformer.pytClientIdleTimeout,
default 5m). Clients are reference counted, so neither the idle close nor a reset ever closes one under a request.
JS keeps the shared client.

On a 421 from per-workspace PyT, doPost and forwardTest count it
(processor_user_transformer_misdirected_requests_total), retire the target's client once per client however many
concurrent chunks got the 421 (processor_user_transformer_client_resets_total), and retry. The fresh client resolves
the target again, so a workspace at zero fails the lookup and goes through the existing cold-start path; the 421
itself never touches the cold-start counter. A 421 that outlasts doPost's retries returns ErrMisdirected, which maps
to 819 like ErrColdStart, so sendBatch keeps retrying instead of panicking. Outside per-workspace PyT a 421 stays a
final 4xx.

transformerclient gains NewClosableClient, returning the client together with the func that releases it.
- sendBatch's retry error carries the 819 body, so the log tells a misdirected request from a cold start; a 421 is
  no longer logged a second time by doPost's retry notify.
- doPost defers the pyt client's release right after acquiring it; the registry is built before the options run,
  so WithClient sets its factory directly and Client.newPyTClient is gone.
- One error text for a persistent 421 or cold start, the 819 rationale kept once, docs corrected on field
  immutability, NewClosableClient and forwardTest's deadline, plus why the idle default is 5m.
- Tests: the reset through New's real httplb factory, a forward-path 421 followed by a failed lookup, the idle
  timeout key; the current-pod test can no longer pass without a reset, the httplb close test fails instead of
  hanging, the stdlib close test checks the dropped connection, and test helpers get test-specific names.
@codecov

codecov Bot commented Oct 16, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 84.60%. Comparing base (8b5c22d) to head (6780103).

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #7494      +/-   ##
==========================================
+ Coverage   84.54%   84.60%   +0.06%     
==========================================
  Files         632      633       +1     
  Lines       62839    62923      +84     
==========================================
+ Hits        53128    53239     +111     
+ Misses       9708     9681      -27     
  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.

fracasula and others added 8 commits October 19, 2026 10:10
…421 reason

- onMisdirected passes X-Rudder-Error-Reason through retryReasonTag before it reaches the log and the
  ErrMisdirected error, and from there the 819 body, sendBatch's retry log and failed events.
- Tests: a slow close holds up neither the release that starts it nor other targets, from both the retire and the
  idle path; WithClient's client serves pyt targets and is never closed by the registry; the reason is bounded for
  an over-long, a per-request and a missing value. The JS 421 test runs with bounded retries, so a regression fails
  instead of hanging, and the real-client close check no longer calls require inside Eventually.
- Comments: an idle timeout <=0 closes a client after every request; forwardTest keeps its retry log for a 421
  because a dashboard panel reads it.
…-on-421' of github.com:rudderlabs/rudder-server into feature/pipe-3553-01-rudder-server-reset-the-pyt-client-on-421
@fracasula
fracasula marked this pull request as ready for review October 19, 2026 15:01
@fracasula
fracasula merged commit 83db4d6 into master Oct 23, 2026
74 checks passed
@fracasula
fracasula deleted the feature/pipe-3553-01-rudder-server-reset-the-pyt-client-on-421 branch October 23, 2026 09:10
itsmihir pushed a commit that referenced this pull request Oct 26, 2026
🤖 I have created a release *beep* *boop*
---


##
[1.92.0-rc.1](v1.91.0...v1.92.0-rc.1)
(2026-10-26)


### Features

* **processor:** pyt test-pod deployer sets PYT_MODE=test
([#7506](#7506))
([a050ed6](a050ed6))
* **processor:** reset the per-workspace pyt client on 421
([#7494](#7494))
([83db4d6](83db4d6))
* **router:** re-fetch the cached OAuth token when the control plane
holds a newer secret (PRO-5947)
([#7478](#7478))
([742779d](742779d))
* **router:** tag oauth_action counters with destinationId and count
AUTH_STATUS_INACTIVE (PRO-5946)
([#7477](#7477))
([0e15eb4](0e15eb4))


### Bug Fixes

* flaky TestDrainConfigRoutine failing with "database is closed"
([#7489](#7489))
([9baa89f](9baa89f))


### Miscellaneous

* block new ginkgo/gomega usage in tests
([#7502](#7502))
([e1c9d38](e1c9d38))
* bump dependency versions
([#7522](#7522))
([1067ff4](1067ff4))
* enforce errors.AsType and point CLAUDE.md at AGENTS.md
([#7521](#7521))
([5c7e088](5c7e088))
* go 1.27.3
([#7516](#7516))
([3c240a3](3c240a3))
* migrate debugger, services, async destination and utils tests from
ginkgo to testify
([#7503](#7503))
([1a8c85a](1a8c85a))
* migrate gateway, rsources, reporting, batchrouter and manager tests
from ginkgo to testify
([#7507](#7507))
([ffdd505](ffdd505))
* remove ginkgo and gomega from tests
([#7508](#7508))
([d3e7e0f](d3e7e0f))

---
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 Oct 27, 2026
🤖 I have created a release *beep* *boop*
---


##
[1.92.0](v1.91.0...v1.92.0)
(2026-10-26)


### Features

* **processor:** pyt test-pod deployer sets PYT_MODE=test
([#7506](#7506))
([a050ed6](a050ed6))
* **processor:** reset the per-workspace pyt client on 421
([#7494](#7494))
([83db4d6](83db4d6))
* **router:** re-fetch the cached OAuth token when the control plane
holds a newer secret (PRO-5947)
([#7478](#7478))
([742779d](742779d))
* **router:** tag oauth_action counters with destinationId and count
AUTH_STATUS_INACTIVE (PRO-5946)
([#7477](#7477))
([0e15eb4](0e15eb4))


### Bug Fixes

* flaky TestDrainConfigRoutine failing with "database is closed"
([#7489](#7489))
([9baa89f](9baa89f))


### Miscellaneous

* block new ginkgo/gomega usage in tests
([#7502](#7502))
([e1c9d38](e1c9d38))
* bump dependency versions
([#7522](#7522))
([1067ff4](1067ff4))
* enforce errors.AsType and point CLAUDE.md at AGENTS.md
([#7521](#7521))
([5c7e088](5c7e088))
* go 1.27.3
([#7516](#7516))
([3c240a3](3c240a3))
* migrate debugger, services, async destination and utils tests from
ginkgo to testify
([#7503](#7503))
([1a8c85a](1a8c85a))
* migrate gateway, rsources, reporting, batchrouter and manager tests
from ginkgo to testify
([#7507](#7507))
([ffdd505](ffdd505))
* remove ginkgo and gomega from tests
([#7508](#7508))
([d3e7e0f](d3e7e0f))

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