fix(linter): fix Arc<ModuleRecord> memory leak and lifecycle issues#14049
fix(linter): fix Arc<ModuleRecord> memory leak and lifecycle issues#14049
Conversation
How to use the Graphite Merge QueueAdd either label to this PR to merge it via the merge queue:
You must have a Graphite account in order to use the merge queue. Sign up using this link. An organization admin has enabled the Graphite Merge Queue in this repository. Please do not merge from GitHub as this will restart CI on PRs being processed by the merge queue. |
There was a problem hiding this comment.
Pull Request Overview
This PR fixes memory leaks and lifecycle issues with Arc<ModuleRecord> management in the linter's runtime by switching to weak references and properly managing the module cache lifetime.
- Changed
loaded_modulesfromArc<ModuleRecord>toWeak<ModuleRecord>to break circular dependencies - Moved module cache (
modules_by_pathandencountered_paths) to Runtime struct fields with proper lifecycle management - Added module cache clearing after linting completes to prevent memory leaks
Reviewed Changes
Copilot reviewed 12 out of 13 changed files in this pull request and generated 4 comments.
| File | Description |
|---|---|
crates/oxc_linter/src/service/runtime.rs |
Major refactoring to use Mutex-wrapped module caches as struct fields, switch to weak references, and add proper cleanup |
crates/oxc_linter/src/module_record.rs |
Changed loaded_modules to use Weak<ModuleRecord> and added helper method for safe upgrades |
crates/oxc_linter/src/module_graph_visitor.rs |
Updated to handle weak references with proper upgrade checks |
| Import rule files | Updated to use new get_loaded_module() helper method instead of direct weak reference access |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
CodSpeed Instrumentation Performance ReportMerging #14049 will not alter performanceComparing Summary
|
81c02c0 to
0e76665
Compare
|
Tested with heaptrack and memory stats. After 1000x iteration with the example code in #12100 In this PR: Looks like there are more problems with the server :( |
529b7c7 to
8e458f4
Compare
|
I tested through variables methods:
|
After #14049, the fixtures files are not needed anymore. They were only files which simplified the bug search
Summary
Fixes #10627
This PR fixes two critical issues with
Arc<ModuleRecord>management in the linter's runtime:Arc<ModuleRecord>instances weren't being dropped after program exitsWeakreferences forCachedPathto enable proper drop oxc-resolver#727Changes
1. Use Weak references to break circular dependencies
loaded_modulesfield fromArc<ModuleRecord>toWeak<ModuleRecord>get_loaded_module()helper method for safe weak reference upgrades2. Fix ModuleRecord lifecycle management
modules_by_pathandencountered_pathsfields of the Runtime struct (with Mutex wrapping)resolve_modulesthat was causing ModuleRecords to disappearrun,run_source,run_test_source)Technical Details
The root cause was that
modules_by_pathwas being cleared while parallel linting tasks spawned byrayon::scopewere still running. This caused:loaded_modulesto become invalidThe fix ensures that:
Test Plan
🤖 Generated with Claude Code