Fix/re2 wasm heap leak#210
Open
costateixeira wants to merge 3 commits into
Open
Conversation
f3c848f to
119d46f
Compare
re2-wasm has a fixed 16 MB WASM linear-memory heap with no real free(): every `new RE2(pattern, flags)` permanently consumes a few KB regardless of whether the JS object is later GC'd. After enough compiles the heap is full and any further call aborts with `Cannot enlarge memory arrays to size 16781312 bytes (OOM)`. Reproducer: compiling the same trivial pattern 2965 times in a loop is enough to OOM on a fresh Node process. In production tx.fhir.org hit this via repeated $validate-code calls against the IPS lab-observations ValueSet, whose LOINC `CLASS regex` filter is recompiled per call. Cache compiled RE2 objects by (pattern, flags). Same pattern -> single compile -> single leak. Does not fix the underlying leak; a proper fix is to replace re2-wasm with the native `re2` package, which has real free() semantics.
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.
https://chat.fhir.org/#narrow/channel/179252-IG-creation/topic/crash.20tx.2Efhir.2Eorg.3F/with/594892934
re2-wasm has a fixed 16 MB WASM linear-memory heap with no real free():
every
new RE2(pattern, flags)permanently consumes a few KB regardless of whether the JS object is later GC'd. After enough compiles the heap is full and any further call aborts withCannot enlarge memory arrays to size 16781312 bytes (OOM).Reproducer: compiling the same trivial pattern 2965 times in a loop is enough to OOM on a fresh Node process. In production tx.fhir.org hit this via repeated $validate-code calls against the IPS lab-observations ValueSet, whose LOINC
CLASS regexfilter is recompiled per call.Cache compiled RE2 objects by (pattern, flags). Same pattern -> single compile -> single leak. Does not fix the underlying leak;
a proper fix is to replace re2-wasm with the native
re2package, which has real free() semantics.