fix(router): release executor schema refs on graphMux shutdown#3011
fix(router): release executor schema refs on graphMux shutdown#3011arutkowski00 wants to merge 1 commit into
Conversation
Add Executor.Close() to nil federation/client schemas, plan config, and resolver after the mux drains in-flight work and closes plan caches, so the previous graph generation can be garbage-collected after hot-reload.
|
Warning Review limit reached
More reviews will be available in 23 minutes and 54 seconds. Learn how PR review limits work. Your organization has used up its prepaid credits, and credit purchases are no longer available. Enable the review add-on in the billing tab to keep reviews running — you're only billed for reviews past your plan's rate limits ($0.25/file). ⌛ How to resolve this issue?After more reviews become available, a review can be triggered using the To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based credits. 🚦 How do rate limits work?CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability. For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window. Please see our Fair Usage Limits Policy for further information. ℹ️ Review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (3)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
| e.ClientSchema = nil | ||
| e.RouterSchema = nil | ||
| e.PlanConfig = plan.Configuration{} | ||
| e.RenameTypeNames = nil | ||
| e.Resolver = nil |
There was a problem hiding this comment.
The problem is websockets use this Executor and they are closed async. When this function is called websocket connections are still alive (got signaled to close but might take a moment) and might use the Executor, which has just nilled its components. It can cause nil panics or unwanted errors at least. I need to check this in more depth and how to solve it.
| e.RouterSchema = nil | ||
| e.PlanConfig = plan.Configuration{} | ||
| e.RenameTypeNames = nil | ||
| e.Resolver = nil |
There was a problem hiding this comment.
| e.Resolver = nil |
I think we can exclude this one. Compared to the other fields it's not heavy and reduces the risk surface. Also this executor instance the pointer points to is referenced by other pointers in other places as well (the WS handler/graphql handler), which is still active when we are here. So GC can't clean it up immediately anyways.
EDIT: Also fixed by #3010 but review there still pending
|
I did a deeper analysis and found other places this could lead to nil panics. A good risk reduction is described in #3011 (comment) but this alone is not sufficient. There are still races: #1: In-flight request handling can now panic. Any request on the old graph mux unlucky enough to be in parse/normalize/validate/plan when we are here can hit it. Can happen on a busy server. These panics are recovered but technically this should not be hard to fix. #2: When an active WS connection on the old graph mux initiates a new subscription it would panic, no recovery. Best thing would be the WS handler does not accept that anymore since we are about to close it anyways. At least we should have a recovery in place until we come up with a long term solution here. #3: Persisted query cache rewarming can nil panic and crash the router. Rewarming happens on PQL manifest changes. If we are warming the cache (can take seconds) and then we are here the warming callback parses and plans its stored queries and that accesses these fields. Not so likely to happen but still it can crash the router. At the very least we should have a recovery until we have a long term solution. So overall it seems to possible if we omit niling |
Problem
After config hot-reload, the shut-down
Executorretained federation/client schema AST and plan config references, keeping the previous graph generation alive.Fix
Add
Executor.Close()to nil schema, plan config, and resolver references. Call it fromgraphMux.Shutdown()after plan caches are closed.Test plan
TestExecutorCloseReleasesSchemaReferencesgo test ./router/core/...Part of config hot-reload memory leak investigation (monday.com #3221).