Repository navigation
fix(web): stop redefining the authorize method on every request - #552
Merged
Merged
Conversation
AuthorizationConcern#init_authorize ran before every action and called define_method on the controller class, with a block that closed over the controller handling the request. With YJIT on, every superseded definition stays reachable, so each request kept its controller, request, response body and loaded records alive. Web processes grew with every page served until they were OOMKilled. The generated method only existed so dynamic_authorize! could send to it; dynamic_authorize! now calls authorize with the same policy arguments. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: Artem Petrov <[email protected]>
artempartos
added a commit
that referenced
this pull request
Oct 24, 2026
Request logs had an always-empty user field, and MCP calls logged nothing but the path, so tracing a request to an account meant matching SQL binds by request id. The web memory leak fixed in #552 grew for weeks before anyone noticed; a periodic GC.stat/RSS line shows the next one as a trend within a day and tells retained Ruby objects from native memory. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: Artem Petrov <[email protected]>
artempartos
added a commit
that referenced
this pull request
Oct 24, 2026
Request logs had an always-empty user field, and MCP calls logged nothing but the path, so tracing a request to an account meant matching SQL binds by request id. The web memory leak fixed in #552 grew for weeks before anyone noticed; a periodic GC.stat/RSS line shows the next one as a trend within a day and tells retained Ruby objects from native memory. Signed-off-by: Artem Petrov <[email protected]> Co-authored-by: Claude Opus 5.5 <[email protected]>
Merged
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
Web processes grew with every page they served and were eventually OOMKilled. The cause is
AuthorizationConcern#init_authorize: aprepend_before_actionthat, on every request, calledThe block is a closure over the controller handling that request. With YJIT on (the Rails default in production), superseded method definitions stay reachable from YJIT, so every request kept its controller — and through it the request, the response body and every record it loaded — alive for the life of the process. Heavy pages (the board's Inertia payload) made it grow fastest; controllers outside
Web::Company/Api::V1never ran the hook, which is why only web processes grew.The generated
authorize_<name>method existed only sodynamic_authorize!couldsendto it.dynamic_authorize!now callsauthorize(policy_method_params)directly:before_action :dynamic_authorize!in both base controllers), and the existingskip_before_action :dynamic_authorize!call sites are untouched;ancestors.include?(ApplicationController)guard was always true — both classes that include the concern inherit from::ApplicationController;authorize_*methods directly.It also stops invalidating the controller's method caches and YJIT code on every request.
How it was found and verified
Reproduced on a local stand: the production image (v1.6.0) under real Puma, its own Postgres/Redis, a large seeded board, and a plain
net/httpclient issuing the board's cable-triggered partial reloads and task-drawer visits (10 threads). A heap dump (ObjectSpace.dump_all) traced the retained response bodies toBoardsControllerinstances held by aProcreachable fromAuthorizationConcern, rooted at YJIT.Same 1,500-request load, Puma RSS:
Sentry and the debug log level were ruled out on the same stand (growth unchanged with either off).
Tests
test/integration/web/company/authorization_defines_no_methods_test.rbdrives a real company page and asserts the request defines nothing on its controller class (it fails on the old concern). Existing authorization and policy-coverage tests cover the unchanged authorization behaviour. Locally only a syntax check was run; CI is the verification for the suite, rubocop and brakeman.Changelog: one untagged Fixed entry. It also moves the Docs entry from #551 out of
[1.6.0]into[Unreleased]: #551 merged after the 1.6.0 release PR, so its entry landed in a release it is not part of.🤖 Generated with Claude Code