Skip to content

fix(tests): Make test_shutdown.py wait for Relay to be up before proceeding#6226

Merged
klochek merged 1 commit into
masterfrom
christopherklochek/fix_shutdown_flake
Jul 20, 2026
Merged

fix(tests): Make test_shutdown.py wait for Relay to be up before proceeding#6226
klochek merged 1 commit into
masterfrom
christopherklochek/fix_shutdown_flake

Conversation

@klochek

@klochek klochek commented Jul 14, 2026

Copy link
Copy Markdown
Contributor

When we are in the shutting down state (and non-ephemeral), we aren't guaranteed to close the channel fast enough to reject all incoming envelopes. Add back the shutdown handle, but also check to see if we're non-ephemeral. Fixes a flaky test I ran into.

@klochek
klochek requested a review from a team as a code owner July 14, 2026 15:06
Comment thread relay-server/src/services/buffer/mod.rs Outdated
Comment thread relay-server/src/services/buffer/mod.rs Outdated
pub fn try_push(&self, envelope: Managed<Box<Envelope>>) -> Result<(), Rejected<PushError>> {
if self.addr.is_closed() {
// This happens for inflight requests when `ephemeral: false`.
let permanent_shutting_down = !self.is_ephemeral && self.shutdown_handle.shutting_down();

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This should be 'just' another atomic check, but worth keeping an eye on performance metrics on rollout as every request will go through this check, in case it's more than just an atomic (backed by a Tokio Watch).

Comment thread relay-server/src/services/buffer/mod.rs Outdated
@klochek
klochek added this pull request to the merge queue Jul 15, 2026
@klochek
klochek removed this pull request from the merge queue due to a manual request Jul 15, 2026
Comment thread relay-system/src/controller.rs Outdated

@jjbayer jjbayer left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I think we can make this more local: The envelope buffer already gets notified of the shutdown, so it could store an atomic bool on EnvelopeBufferMetrics immediately after shutdown.notified() (before calling Self::handle_shutdown).

Then try_push can simply check self.metrics.is_shutting_down. We might want to rename metrics to something more generic though, because it would now contain more than metrics.

Comment thread relay-system/src/controller.rs Outdated
@jjbayer
jjbayer dismissed their stale review July 17, 2026 08:05

My comment is still relevant but I won't be available to approve the PR.

@klochek
klochek added this pull request to the merge queue Jul 17, 2026
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Jul 17, 2026

@cursor cursor Bot 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.

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit e715c51. Configure here.

Comment thread relay-server/src/services/buffer/mod.rs Outdated
Comment thread relay-server/src/services/buffer/mod.rs
@klochek
klochek force-pushed the christopherklochek/fix_shutdown_flake branch from e715c51 to f1e9280 Compare July 17, 2026 20:26
@klochek klochek changed the title fix(server): Always reject envelopes when shutting down and non-ephemeral fix(tests): make test_shutdown.py wait for Relay to be up before proceeding Jul 17, 2026
@klochek

klochek commented Jul 17, 2026

Copy link
Copy Markdown
Contributor Author

After running into the issue again, I determined that a cause of this flake is that Relay's EnvelopeBufferService might not even have initialized by the time we send the SIGTERM, and so EnvelopeBufferService can just handle the envelope payload before having a chance to respond to the shutdown.

I also realized that dealing with processing on shutdown is inherently racy: there's no way to enforce a "drop if non-ephemeral" policy given that the EnvelopeBufferService can be in any state, and responding to any ready future in its select! loop (envelope bytes, or shutdown signal), so instead, adjust the test to test the thing we want: that a ready Relay will respond to the SIGTERM promptly, and not finish envelope processing.

@klochek
klochek requested a review from Dav1dde July 17, 2026 20:33
@klochek klochek changed the title fix(tests): make test_shutdown.py wait for Relay to be up before proceeding fix(tests): Make test_shutdown.py wait for Relay to be up before proceeding Jul 17, 2026

@Dav1dde Dav1dde left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Nice!

@klochek
klochek added this pull request to the merge queue Jul 20, 2026
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Jul 20, 2026
@klochek
klochek added this pull request to the merge queue Jul 20, 2026
Merged via the queue into master with commit a54c0b2 Jul 20, 2026
37 of 38 checks passed
@klochek
klochek deleted the christopherklochek/fix_shutdown_flake branch July 20, 2026 15:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants