Skip to content

fix(rivetkit): track serverless application listener for graceful shutdown drain - #5673

Open
Tyagiquamar wants to merge 1 commit into
rivet-dev:mainfrom
Tyagiquamar:fix/registry-track-serverless-listener-shutdown
Open

fix(rivetkit): track serverless application listener for graceful shutdown drain#5673
Tyagiquamar wants to merge 1 commit into
rivet-dev:mainfrom
Tyagiquamar:fix/registry-track-serverless-listener-shutdown

Conversation

@Tyagiquamar

Copy link
Copy Markdown

Description

When registry.listen() is invoked in serverless listener mode, it starts runtime.serveListener(registry, ...). During graceful shutdown (registry.shutdown() / #drain()), the drain logic specifically includes:

if (this.#applicationListenerPromise !== undefined) {
    await this.#applicationListenerPromise.catch(() => undefined);
}

However, listen() previously called await runtime.serveListener(...) directly without storing the returned promise into this.#applicationListenerPromise. As a result, this.#applicationListenerPromise remained undefined, and shutdown() would not await or drain the active serverless listener before completing.

This PR assigns this.#applicationListenerPromise = listenerPromise; in listen() prior to awaiting it, ensuring the active serverless listener is tracked and drained as intended during shutdown.

Type of change

  • Bug fix (non-breaking change which fixes an issue)

How Has This Been Tested?

  • Added a unit test in rivetkit-typescript/packages/rivetkit/tests/registry-shutdown.test.ts (waits for in-flight serverless application listener before resolving) asserting that shutdown() waits on the active serveListener promise during drain.
  • Ran pnpm --filter rivetkit test tests/registry-shutdown.test.ts (all 8 tests pass).
  • Formatted with pnpm --filter rivetkit format (Biome).

Checklist:

  • My code follows the style guidelines of this project
  • I have performed a self-review of my code
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes

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.

1 participant