Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions crates/oxc_linter/src/service/runtime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -733,6 +733,15 @@ impl Runtime {
// }
// }

// Clear resolver cache to prevent memory leaks in language server usage.
// The resolver caches filesystem metadata globally, which can accumulate
// indefinitely when processing files repeatedly in a language server context.
// Clearing after each run prevents unbounded memory growth while still
// allowing caching within a single linting session.
if let Some(resolver) = &self.resolver {
resolver.clear_cache();
}

messages.into_inner().unwrap()
}

Expand Down
24 changes: 24 additions & 0 deletions crates/oxc_linter/tests/integration_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,3 +39,27 @@ fn test_declare_oxc_lint() {
// plugin name is passed to const
assert_eq!(TestRule::PLUGIN, "eslint");
}

/// Test to ensure resolver cache clearing doesn't panic when called
#[test]
fn test_resolver_cache_clearing_integration() {
// This test verifies that the resolver cache clearing functionality
// compiles and can be called without panicking.
// The actual memory leak fix is in Runtime::run_source() method.

use oxc_resolver::{ResolveOptions, Resolver};

// Create a resolver similar to how it's done in Runtime::get_resolver
let resolver = Resolver::new(ResolveOptions {
extensions: vec![".js".into(), ".ts".into(), ".jsx".into(), ".tsx".into()],
main_fields: vec!["module".into(), "main".into()],
condition_names: vec!["module".into(), "import".into()],
..ResolveOptions::default()
});

// Test that clear_cache can be called without panicking
resolver.clear_cache();

// If we reach here, the clear_cache method works correctly
println!("Resolver cache clearing integration test passed");
}
Loading