Skip to content

fix(server): flushService evicts every cache entry resolved to the flushed database - #1962

Merged
pyramation merged 2 commits into
mainfrom
feat/flush-service-eviction
Nov 5, 2026
Merged

pyramation merged 2 commits into
mainfrom
feat/flush-service-eviction

Conversation

@pyramation

@pyramation pyramation commented Nov 5, 2026 •

Copy link
Copy Markdown
Contributor

Summary

flushService(opts, databaseId) dropped svcCache / graphileCache entries only for the hostnames the database currently lists (function_resolution.api_hostnames). An entry keyed by a hostname the database no longer lists therefore outlived its row and kept resolving.

Now the flush also walks svcCache and evicts every entry whose resolved databaseId is the flushed one (same key removed from graphileCache), then does the hostname lookup as before. Entries of other databases are untouched.

Second gap, same mechanism: a handler build already in flight when the flush ran finished afterwards and re-inserted itself into graphileCache under the flushed key. Every eviction now goes through evictServiceKey(key) (middleware/cache-generation.ts), which advances a per-key generation; the build in graphile.ts records the generation it started under and, at admission time, releases the instance and fails instead of caching if the generation moved. Coalesced waiters fall through to the existing retry path.

Tests added: flush.test.ts — a cached host that the routing lookup no longer returns is gone after server.flush(databaseId); another database's host stays. graphile-single-flight.test.ts — a build whose key is evicted mid-flight is not admitted (cacheGraphileInstance not called, pgl.release() called once).

Link to Devin session: https://app.devin.ai/sessions/19eee6ccb1fd4fbba8b54678699b3235
Open in Devin Desktop: https://app.devin.ai/desktop/session/19eee6ccb1fd4fbba8b54678699b3235?variant=devin
Requested by: @pyramation

@devin-ai-integration

Copy link
Copy Markdown
Contributor

I'll fix CI failures and address comments from users with write access. I'll skip comments containing "(aside)".

  • Disable automatic comment, CI, and merge conflict monitoring

@luxor-code-review

luxor-code-review Bot commented Nov 5, 2026 •

Copy link
Copy Markdown

Review complete. 🟠 1 high

💬 Inline comments (1)

  • 🟠 In-flight handler creation repopulates graphileCache after flush — flush.ts:98

The PR closes a stale-cache gap in the GraphQL server's flush endpoint: previously only hostnames still present in function_resolution.api_hostnames were evicted, so entries whose routing rows were deleted lingered in memory. A new pre-query sweep in flushService evicts caches by matching stored databaseId, and a test verifies stale hostnames are dropped while entries from other databases are preserved.

Files Change
graphql/server/src/middleware/flush.ts Adds a svcCache/graphileCache sweep keyed on databaseId before the DB hostname query, evicting entries for flushed databases.
graphql/server/src/middleware/__tests__/flush.test.ts Adds a test asserting stale hostname eviction by id-match and preservation of other databases' entries.

Reviewed commit: 8be2509

@luxor-code-review luxor-code-review 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.

Adds a databaseId-based sweep of svcCache/graphileCache entries to the flush middleware so hostnames with deleted routing rows are evicted.

Key findings

  • 🟠 In-flight handler creation repopulates graphileCache after flush — flush.ts:98

Comment thread graphql/server/src/middleware/flush.ts Resolved
@pyramation
pyramation merged commit 56bad2c into main Nov 5, 2026
19 checks passed
@pyramation
pyramation deleted the feat/flush-service-eviction branch November 5, 2026 19:29
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