Fix streamable HTTP memory leak from unstable OpenAPI spec object identity - #335
Open
onematchfox wants to merge 1 commit into
Open
Conversation
…ntity Every new HTTP session called initProxy(), which re-read and JSON.parse()'d the OpenAPI spec from disk, producing a fresh object each time. openapi-client-axios dereferences that document through dereference-json-schema, which caches its (expensive, fully-expanded) output in a process-lifetime Map keyed by the input object's identity, with no eviction. A fresh object on every call defeated that cache on every session and permanently retained a full dereferenced copy of the spec, forever. Cache the parsed spec by (specPath, baseUrl) so repeated sessions share the same object identity, letting the upstream cache actually hit instead of growing unbounded. Verified with heap snapshots: an isolated initProxy() loop went from +23.2MB/300 calls to +237KB/300 calls (98% reduction, remainder is one-time JIT warmup, not a leak), and a full end-to-end run (server as a separate process, sessions properly terminated via DELETE) plateaus after an initial JIT warmup with no further growth between 100 and 300 cycles. Fixes makenotion#144 Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Author
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.

Description
Every new HTTP session called
initProxy(), which re-read andJSON.parse()'d the OpenAPI spec from disk, producing a fresh object each time.openapi-client-axiosdereferences that document throughdereference-json-schema, which caches its output in a process-lifetime Map keyed by the input object's identity, with no eviction. A fresh object on every call defeated that cache on every session and permanently retained a full dereferenced copy of the spec, forever - see #144.Cache the parsed spec by
(specPath, baseUrl)so repeated sessions share the same object identity, letting the upstream cache actually hit instead of growing unbounded. Verified with heap snapshots: an isolatedinitProxy()loop went from +23.2MB/300 calls to +237KB/300 calls (98% reduction, remainder is one-time JIT warmup, not a leak), and a full end-to-end run (server as a separate process, sessions properly terminated viaDELETE) plateaus after an initial JIT warmup with no further growth between 100 and 300 cycles.Closes #144.
How was this change tested?
Screenshots