You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
fix(graphql): recover schema caches after listener interruptions - #1999
GraphQL servers recover schema freshness after their PostgreSQL notification connection is interrupted. Previously, a connection that ended without an error or silently stalled could leave HTTP serving cached schemas indefinitely. Even a successful reconnect could retain schemas changed while disconnected, because PostgreSQL does not replay missed notifications.
This completes the listener recovery path alongside the cache eviction and in-flight build fixes in #1962 and #1977.
Handle connection errors and end, destroy failed sessions, and coalesce reconnect attempts with a 5-second retry delay.
Probe the held session every 30 seconds; bound LISTEN and heartbeat queries to 5 seconds. Shutdown cancels timers and discards late connections without waiting for UNLISTEN.
After LISTEN succeeds, invalidate routing, GraphQL handler, and storage discovery caches. Advance a global generation so pending builds cannot restore stale handlers.
Fence routing lookups and requests that resolved their API before invalidation. Re-resolve rather than caching or building from the old configuration.
Catch notification flush failures and invalidate all services conservatively. Log subscription success only after LISTEN completes.
Recovery clears process-wide caches and can cause a temporary burst of schema builds. This PR changes the server package only; no database migration, Cloud configuration, or deployment is included.
Validation
Built the server-test dependency closure and the final server package.
Server unit suite: 292 tests passed across 27 suites.
PostgreSQL HTTP integration: 8 tests passed across 2 suites, including existing scoped routing coverage.
The new integration test warms a real GraphQL schema, terminates the listener backend, commits DDL and a missed notification, verifies the old schema during the gap, then verifies the rebuilt schema after reconnect and a subsequent notification-driven update.
Regression tests cover end-only disconnects, stalled LISTEN/heartbeat, late completion, shutdown, overlapping connection attempts, cache invalidation, and lookups/builds crossing recovery. The end-only, missed-cache, and pending-route tests were observed failing before their fixes.
ESLint on changed TypeScript files and git diff --check passed.
Based on freshly fetched main at 92e15c0778465b2c51f32dbf6de8a44e2160ef92. No devnet recovery or deployment was performed.
🟢 Latched listenerConnecting flag blocks listener recovery (server.ts:277) — The rewritten addEventListener (graphql/server/src/server.ts:277-287) sets this.listenerConnecting = true before calling this.getPool().connect(...), and the flag is only reset inside the connect callback.
This PR reworks the server middleware pipeline: cache-generation invalidation and single-flight admission in graphql/server/src/middleware/cache-generation.ts and api.ts, a rewritten flush path in flush.ts, and single-flight-aware graphile middleware in graphile.ts. The notify LISTEN listener in graphql/server/src/server.ts gains a latched listenerConnecting flag and stricter close/cleanup semantics, with its contract documented in graphql/server/README.md. New and updated tests in graphql/server/src/middleware/__tests__/ and graphql/server-test/__tests__/ cover flush ordering, routing, single-flight behavior, and listener lifecycle including reconnect and shutdown races.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
GraphQL servers recover schema freshness after their PostgreSQL notification connection is interrupted. Previously, a connection that ended without an error or silently stalled could leave HTTP serving cached schemas indefinitely. Even a successful reconnect could retain schemas changed while disconnected, because PostgreSQL does not replay missed notifications.
This completes the listener recovery path alongside the cache eviction and in-flight build fixes in #1962 and #1977.
end, destroy failed sessions, and coalesce reconnect attempts with a 5-second retry delay.Recovery clears process-wide caches and can cause a temporary burst of schema builds. This PR changes the server package only; no database migration, Cloud configuration, or deployment is included.
Validation
git diff --checkpassed.Based on freshly fetched
mainat92e15c0778465b2c51f32dbf6de8a44e2160ef92. No devnet recovery or deployment was performed.