Repository navigation
fix: accept Next.js static-export file names, and serve a request whose service changed mid-build - #1977
Conversation
…export file names A Next.js static export names its segment-prefetch files with ! (a route group as ! plus base64url), $ (a dynamic segment) and @ (a parallel-route slot). The custom key rule rejected all three, so one such file failed a whole site deploy.
… handler build A schema change flushes the service as it lands. A request that had started the handler build just before that got 'service ... was invalidated while its handler was being built' as an internal error, although the next request succeeded. The request now resolves its service again and builds with it, up to three resolutions, so a service that keeps changing still fails with the reason. A build's finally block also no longer deletes a newer build's in-flight entry.
|
Review complete. 🟡 2 medium 💬 Inline comments (2)
🧹 Nitpicks (1) — 🟢 1 low
The PR extends the custom presigned-URL key validator's middle-alphabet character set and adds matching rejection tests. The bulk of the change is a rework of the single-flight
Reviewed commit: 3fc316a |
There was a problem hiding this comment.
Adds !, $, and @ to the allowed custom S3 object-key alphabet with test coverage, and refactors the single-flight schema-handler resolution in the GraphQL middleware with bounded retries and an exported isApiError guard.
Key findings
- 🟡 Retry-path errors leak internal
svc_keydetails to clients — graphile.ts:483 - 🟡 Failed
realtimeManager.stop()skipspgl.release()— graphile.ts:418
| throw new HandlerCreationError(`Failed to create handler for ${key}: the service no longer resolves`, { | ||
| cacheKey: key | ||
| }); |
There was a problem hiding this comment.
🟡 security · medium
Retry-path errors leak internal svc_key details to clients
On the re-resolution path, HandlerCreationError messages embed the internal service cache key — Failed to create handler for ${key}: the service no longer resolves (graphql/server/src/middleware/graphile.ts:483) — and the outer catch forwards e.message verbatim into errors.INTERNAL_FAILURE({ details }) (graphile.ts:499-501), which respondWithGraphQLError serializes into the client-visible error body. If getApiConfig throws inside the retry (resolution diagnostics embedding schema lists, hosts, and database ids), that raw message is surfaced too. Clients learn internal cache-key naming and resolution-plane details on every failed re-resolution.
📋 Prompt for AI Agents
In graphql/server/src/middleware/graphile.ts lines 468-506: wrap the getApiConfig(opts as ApiOptions, req) call at line 481 in its own try/catch so a resolution throw does not propagate raw; and replace the client-visible detail strings so details never contains the internal key or the cause's raw message — use a fixed generic detail such as 'the service is being reconfigured' for both the 'no longer resolves' and MAX_SERVICE_RESOLUTIONS HandlerCreationError cases (lines 475-485), keeping full context in the adjacent log calls. Why: these messages reach the outer catch at lines 494-503 and are serialized to clients via respondWithGraphQLError.
| await instance.realtimeManager?.stop(); | ||
| await instance.pgl.release(); | ||
| throw new ServiceInvalidatedError(key); |
There was a problem hiding this comment.
🟡 bug · medium
Failed realtimeManager.stop() skips pgl.release()
On the service-invalidated teardown path, await instance.realtimeManager?.stop() and await instance.pgl.release() run as sequential awaits with no cleanup guard (graphql/server/src/middleware/graphile.ts:418-419). If stop() rejects, pgl.release() never runs and the builder's pool client/handle leaks — and the rejected error replaces the ServiceInvalidatedError signal so coalesced waiters also miss the invalidation path. The instance is discarded either way, so the leak is permanent for that build.
📋 Prompt for AI Agents
In graphql/server/src/middleware/graphile.ts lines 417-421, replace the sequential awaits with a try/finally: attempt await instance.realtimeManager?.stop() inside the try (log or swallow its error), call await instance.pgl.release() in the finally block, and still throw new ServiceInvalidatedError(key) afterwards so coalesced waiters keep the invalidation signal.
…release a discarded build Review of the handler rebuild: - A handler failure reached the client as 'Failed to create handler for <service key>: …', and the key of a header-routed request names the database and its schemas. The message now says 'this API'; the key stays in the log and the error's context. A re-resolution that throws answers a fixed reason. - A failing realtime teardown skipped releasing the discarded build. Both steps now run, and the invalidation still reaches the waiters. - A service that no longer resolves after the rebuild answers 404, as a fresh request for it does, not 500.
Summary
Two fixes found while dogfooding the desktop's fast path and Deploy on devnet.
Accept the file names a Next.js static export writes
A Next 16 static export names its segment-prefetch files with characters the custom-key rule rejected, so one such file failed a whole site deploy (
INVALID_KEY: must start with alphanumeric or underscore …):__next.!KGFwcCk.__PAGE__.txt!plus its base64url name ((app))tools/__next.$d$id.__PAGE__.txt$<type>$<name>inbox/__next.@modal.__PAGE__.txtcustom-key.tsallows!,$and@after the first character. None of them is percent-encoded in a URL path, so the key a browser asks for is the key that was stored..., leading-slash and NUL checks are unchanged. A key still can't start with one of the three.Serve a request whose service changed during its handler build
Right after a schema build, a request to the new tenant API could fail with
Failed to create handler for api-<db>…: service … was invalidated while its handler was being built, though the next request succeeded. The schema change's flush evicts the service while the first handler build is running. That build is released, as before, but the request that started it, and any coalesced waiter, used to return the error.sequenceDiagram participant R as request participant G as graphile middleware participant F as flush (schema change) R->>G: handler for service key G->>G: build handler (generation n) F->>G: evictServiceKey (generation n+1) G->>G: release stale build G->>G: getApiConfig() again, build again G-->>R: served by the new handlergraphile.ts: an invalidated build throwsServiceInvalidatedError. The request resolves its service again (getApiConfig, the same resolver the api middleware uses), setsreq.api, and goes through the cache, coalescing and build phases again.finallydeletes only its own in-flight entry, never a newer build's.🤖 Generated with Claude Code
https://claude.ai/code/session_017WbsG7JQsKEMKNgVsc4psk