Fix GraalJS resource lifecycle in ScriptMediator to prevent heap growth#2568
Fix GraalJS resource lifecycle in ScriptMediator to prevent heap growth#2568ochnios wants to merge 1 commit into
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (2)
📝 WalkthroughDescriptionThis PR resolves a resource lifecycle issue in the ScriptMediator that causes heap growth when using GraalJS, which became apparent after the Micro Integrator upgraded to Graal version 25.0.2. The issue manifests as steady memory accumulation leading to OutOfMemoryError under sustained load, even with minimal scripts. ChangesScriptMediator lifecycle managementThe
Test coverageTwo new test cases verify the behavior of inline mediators with Graal contexts across multiple mediations:
ImpactThese changes ensure GraalJS resources are properly released after each invocation, preventing repeated calls from accumulating memory overhead. The fix has been validated in a custom build and resolves the reported OutOfMemoryError issues under sustained load. Walkthrough
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
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 |
Purpose
This PR aims to resolve wso2/product-integrator-mi#4949
A custom
synapse-extensionsbuild with this change applied no longer reproduces the problem in my validation.Goals
Ensure GraalJS resources are released after each mediation so repeated invocations do not lead to heap growth and eventual OOM.
Approach
The observed leak pattern points to a per-invocation resource lifecycle issue in
ScriptMediator. The underlying problem is likely deeper in the Graal engine layer and became visible after the Graal version upgrade on the Micro Integrator side (22.3.4 -> 25.0.2). It is also possible that the leak was introduced elsewhere in thewso2-synapsestack but I was not able to identify the exact root cause.The fixes applied:
Context.leave()is still called for GraalJS, but the context is now also closed afterwards.Further enhancements
This fix is intentionally minimal, potential follow-up improvements include sharing a Graal Engine, adding ManagedLifecycle cleanup on undeploy/redeploy, and closing overflow engines when the pool drops them.