Skip to content

fix: ensure canonicalized paths remain accessible via strong references#733

Merged
Boshen merged 1 commit intomainfrom
fix-canonicalized-path-dropped
Sep 28, 2025
Merged

fix: ensure canonicalized paths remain accessible via strong references#733
Boshen merged 1 commit intomainfrom
fix-canonicalized-path-dropped

Conversation

@Boshen
Copy link
Copy Markdown
Member

@Boshen Boshen commented Sep 28, 2025

Summary

  • Fixes Canonicalized path was dropped error #732 - "Canonicalized path was dropped" error that could occur in CI environments
  • Ensures canonicalized paths have at least one strong reference in the cache to prevent premature dropping
  • Adds comprehensive tests to prevent regression

Problem

The resolver was experiencing "Canonicalized path was dropped" errors due to weak references being used without ensuring a strong reference existed. When canonicalize_impl stored only weak references to canonicalized paths, if those paths weren't already in the cache, the Arc would be immediately dropped, causing the weak reference to fail on upgrade.

Solution

Modified canonicalize_impl in src/cache/cache_impl.rs to ensure canonicalized paths are added to the cache (if not already present) before downgrading to weak references. This maintains at least one strong reference while preserving the weak reference pattern needed to avoid memory leaks from circular references.

Test Plan

  • Added test_canonicalized_path_not_dropped to verify canonicalization works correctly
  • Added test_canonicalized_path_weak_reference to ensure the error doesn't occur
  • All existing tests pass, including the memory leak test
  • cargo test passes
  • cargo clippy passes
  • cargo check passes

🤖 Generated with Claude Code

@graphite-app
Copy link
Copy Markdown

graphite-app bot commented Sep 28, 2025

How to use the Graphite Merge Queue

Add the label merge to this PR to add it to 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.

@codecov
Copy link
Copy Markdown

codecov bot commented Sep 28, 2025

Codecov Report

❌ Patch coverage is 66.66667% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 94.58%. Comparing base (cebe9fc) to head (9e971fa).
⚠️ Report is 3 commits behind head on main.

Files with missing lines Patch % Lines
src/cache/cache_impl.rs 66.66% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #733      +/-   ##
==========================================
- Coverage   94.64%   94.58%   -0.06%     
==========================================
  Files          15       15              
  Lines        2914     2920       +6     
==========================================
+ Hits         2758     2762       +4     
- Misses        156      158       +2     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@Boshen Boshen force-pushed the fix-canonicalized-path-dropped branch from 395834e to b70e409 Compare September 28, 2025 08:13
Fixes #732 - "Canonicalized path was dropped" error that could occur in CI environments.

The issue was that canonicalized paths were only stored as weak references without ensuring
a strong reference existed in the cache. This could cause the Arc to be immediately dropped,
leading to the weak reference failing to upgrade.

The fix ensures canonicalized paths are added to the cache (if not already present) before
downgrading to weak references, maintaining at least one strong reference while preserving
the weak reference pattern needed to avoid memory leaks.

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <[email protected]>
@Boshen Boshen force-pushed the fix-canonicalized-path-dropped branch from b70e409 to 9e971fa Compare September 28, 2025 08:16
@Boshen Boshen added the merge label Sep 28, 2025
Copy link
Copy Markdown
Member Author

Boshen commented Sep 28, 2025

Merge activity

  • Sep 28, 8:17 AM UTC: The merge label 'merge' was detected. This PR will be added to the Graphite merge queue once it meets the requirements.
  • Sep 28, 8:18 AM UTC: Boshen added this pull request to the Graphite merge queue.
  • Sep 28, 8:20 AM UTC: The Graphite merge queue couldn't merge this PR because it failed for an unknown reason.

@codspeed-hq
Copy link
Copy Markdown

codspeed-hq bot commented Sep 28, 2025

CodSpeed Performance Report

Merging #733 will not alter performance

Comparing fix-canonicalized-path-dropped (9e971fa) with main (7c29092)

Summary

✅ 7 untouched
⏩ 2 skipped1

Footnotes

  1. 2 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports.

@Boshen Boshen merged commit 4cd0893 into main Sep 28, 2025
14 checks passed
@Boshen Boshen deleted the fix-canonicalized-path-dropped branch September 28, 2025 08:19
graphite-app bot pushed a commit that referenced this pull request Sep 28, 2025
…es (#733)

## Summary

- Fixes #732 - "Canonicalized path was dropped" error that could occur in CI environments
- Ensures canonicalized paths have at least one strong reference in the cache to prevent premature dropping
- Adds comprehensive tests to prevent regression

## Problem

The resolver was experiencing "Canonicalized path was dropped" errors due to weak references being used without ensuring a strong reference existed. When `canonicalize_impl` stored only weak references to canonicalized paths, if those paths weren't already in the cache, the Arc would be immediately dropped, causing the weak reference to fail on upgrade.

## Solution

Modified `canonicalize_impl` in `src/cache/cache_impl.rs` to ensure canonicalized paths are added to the cache (if not already present) before downgrading to weak references. This maintains at least one strong reference while preserving the weak reference pattern needed to avoid memory leaks from circular references.

## Test Plan

- [x] Added `test_canonicalized_path_not_dropped` to verify canonicalization works correctly
- [x] Added `test_canonicalized_path_weak_reference` to ensure the error doesn't occur
- [x] All existing tests pass, including the memory leak test
- [x] `cargo test` passes
- [x] `cargo clippy` passes
- [x] `cargo check` passes

🤖 Generated with [Claude Code](https://claude.ai/code)
@graphite-app graphite-app bot removed the merge label Sep 28, 2025
This was referenced Sep 28, 2025
shulaoda pushed a commit to shulaoda/oxc-resolver that referenced this pull request Mar 28, 2026
## 🤖 New release

* `oxc_resolver`: 8.0.0 -> 9.0.0 (⚠ API breaking changes)
* `oxc_napi_resolver`: 8.0.0

### ⚠ `oxc_resolver` breaking changes

```text
--- failure constructible_struct_adds_field: externally-constructible struct adds field ---

Description:
A pub struct constructible with a struct literal has a new pub field. Existing struct literals must be updated to include the new field.
        ref: https://doc.rust-lang.org/reference/expressions/struct-expr.html
       impl: https://github.com/obi1kenobi/cargo-semver-checks/tree/v0.40.0/src/lints/constructible_struct_adds_field.ron

Failed in:
  field ResolveOptions.modules in /tmp/.tmpTBvVad/oxc-resolver/src/options.rs:114

--- failure trait_method_added: pub trait method added ---

Description:
A non-sealed public trait added a new method without a default implementation, which breaks downstream implementations of the trait
        ref: https://doc.rust-lang.org/cargo/reference/semver.html#trait-new-item-no-default
       impl: https://github.com/obi1kenobi/cargo-semver-checks/tree/v0.40.0/src/lints/trait_method_added.ron

Failed in:
  trait method oxc_resolver::CachedPath::module_directory in file /tmp/.tmpTBvVad/oxc-resolver/src/cache.rs:69
  trait method oxc_resolver::CachedPath::cached_node_modules in file /tmp/.tmpTBvVad/oxc-resolver/src/cache.rs:76
```

<details><summary><i><b>Changelog</b></i></summary><p>

## `oxc_resolver`

<blockquote>

##
[9.0.0](oxc-project/oxc-resolver@oxc_resolver-v8.0.0...oxc_resolver-v9.0.0)
- 2025-05-09

### <!-- 1 -->Bug Fixes

- hash import does not need to load from node_modules
([oxc-project#501](oxc-project#501))

### <!-- 7 -->Chore

- add `--tsconfig` to example
([oxc-project#505](oxc-project#505))
- publish `oxc_napi_resolver`
([oxc-project#496](oxc-project#496))
</blockquote>

## `oxc_napi_resolver`

<blockquote>

##
[8.0.0](https://github.com/oxc-project/oxc-resolver/releases/tag/oxc_napi_resolver-v8.0.0)
- 2025-05-09

### <!-- 0 -->Features

- *(napi)* add mimalloc
([oxc-project#423](oxc-project#423))
- [**breaking**] Rust Edition 2024
([oxc-project#402](oxc-project#402))
- expose `package_json_path`
([oxc-project#376](oxc-project#376))
- *(napi)* expose module type info in ResolveResult
([oxc-project#223](oxc-project#223))
- *(napi)* add tracing via `OXC_LOG:DEBUG`
([oxc-project#202](oxc-project#202))
- *(napi)* add async API
([oxc-project#191](oxc-project#191))
- add `imports_fields` option
([oxc-project#138](oxc-project#138))
- add more builder functions for options
([oxc-project#110](oxc-project#110))
- *(napi)* support wasi target
([oxc-project#31](oxc-project#31))
- add file_dependencies and missing_dependencies API
([oxc-project#50](oxc-project#50))
- *(napi)* expose cloneWithOptions and clearCache methods
([oxc-project#40](oxc-project#40))
- *(napi)* update the doc and type for tsconfig references
([oxc-project#24](oxc-project#24))
- *(napi)* add options
([oxc-project#19](oxc-project#19))
- *(resolver)* add tracing-subscriber feature
([oxc-project#904](oxc-project#904))
- *(resolver)* tsconfig project references
([oxc-project#862](oxc-project#862))
- *(resolver)* add thiserror
([oxc-project#847](oxc-project#847))
- *(resolver)* implement nested alias field
([oxc-project#795](oxc-project#795))
- *(resolver)* implement tsconfig-paths
([oxc-project#750](oxc-project#750))
- *(resolver)* implement configurable `exports_fields` option
([oxc-project#733](oxc-project#733))
- *(resolver)* implement `main_fields`
- *(resolver)* implement resolveToContext
([oxc-project#694](oxc-project#694))
- *(resolver)* implement restrictions (path only)
([oxc-project#693](oxc-project#693))
- *(resolver)* implement fully specified
([oxc-project#687](oxc-project#687))
- *(resolver)* imports field
([oxc-project#681](oxc-project#681))
- *(resolver)* finish most of exports field
([oxc-project#674](oxc-project#674))
- *(resolver)* port the rest of the exports field tests
([oxc-project#659](oxc-project#659))
- *(resolver)* implement symlinks
([oxc-project#582](oxc-project#582))
- *(resolver)* complete query and fragment parsing
([oxc-project#579](oxc-project#579))
- *(resolver)* add preferRelative and preferAbsolute
([oxc-project#577](oxc-project#577))
- *(resolver)* implement roots
([oxc-project#576](oxc-project#576))
- *(resolver)* implement fallback
([oxc-project#572](oxc-project#572))
- *(resolver)* implement enforceExtension
([oxc-project#566](oxc-project#566))
- *(resolver)* implement descriptionFiles option
([oxc-project#565](oxc-project#565))
- *(resolver)* implement the basics of path alias
([oxc-project#564](oxc-project#564))
- *(resolver)* accept different file system implementations
([oxc-project#562](oxc-project#562))
- *(resolver)* implement browser field
([oxc-project#561](oxc-project#561))
- *(resolver)* implement scoped packages
([oxc-project#558](oxc-project#558))
- *(resolver)* port incorrect description file test
([oxc-project#557](oxc-project#557))
- *(resolver)* implement extension_alias
([oxc-project#556](oxc-project#556))
- *(resolver)* port resolve tests
([oxc-project#555](oxc-project#555))
- *(resolver)* resolve extensions
([oxc-project#549](oxc-project#549))
- *(resolver)* add resolver test fixtures
([oxc-project#542](oxc-project#542))

### <!-- 1 -->Bug Fixes

- hash import does not need to load from node_modules
([oxc-project#501](oxc-project#501))
- *(napi)* `new ResolverFactory()` options should be optional
([oxc-project#256](oxc-project#256))
- *(napi)* update buggy NAPI-RS versions
([oxc-project#225](oxc-project#225))
- canonicalize is not supported on wasi target
([oxc-project#124](oxc-project#124))
- resolve "browser" field when "exports" is present
([oxc-project#59](oxc-project#59))

### <!-- 4 -->Refactor

- [**breaking**] remove `description_files` option
([oxc-project#488](oxc-project#488))
- [**breaking**] remove `modules` options
([oxc-project#484](oxc-project#484))
- vitest ([oxc-project#380](oxc-project#380))
- apply latest `cargo +nightly fmt`
([oxc-project#281](oxc-project#281))
- selectively parse package_json fields instead of parsing everything
([oxc-project#103](oxc-project#103))
- *(resolver)* clean up some code and tests
- *(resolver)* change internal funcs to non-pub by moving to unit tests
([oxc-project#682](oxc-project#682))

### <!-- 7 -->Chore

- publish `oxc_napi_resolver`
([oxc-project#496](oxc-project#496))
- *(napi)* make mimalloc optional to build
([oxc-project#495](oxc-project#495))
- *(README)* add wasm usage example
- *(README)* crates.io badge use recent downloads
- *(napi)* auto download wasm binding on webcontainer
([oxc-project#471](oxc-project#471))
- use root package.json for napi build
([oxc-project#469](oxc-project#469))
- *(deps)* update github-actions
([oxc-project#444](oxc-project#444))
- *(deps)* lock file maintenance npm packages
([oxc-project#436](oxc-project#436))
- bump napi
([oxc-project#404](oxc-project#404))
- *(deps)* lock file maintenance npm packages
([oxc-project#391](oxc-project#391))
- *(deps)* lock file maintenance rust crates
([oxc-project#390](oxc-project#390))
- *(README)* clarify Rust and node.js usages
- add dprint
([oxc-project#326](oxc-project#326))
- *(deps)* update napi-rs to 3.0.0-alpha
- `cargo upgrade` && `pnpm upgrade`
- *(deps)* update napi-rs to 3.0.0-alpha
- update napi changes
- *(deps)* update rust crate napi-derive to 3.0.0-alpha
- *(deps)* update rust crate napi to 3.0.0-alpha
- *(deps)* update napi-rs to 2.16.8
- *(napi)* make napi binary smaller with minimal tracing features
([oxc-project#213](oxc-project#213))
- *(napi)* remove tokio
([oxc-project#212](oxc-project#212))
- document directory is an absolute path for `resolve(directory,
specifier)`
([oxc-project#206](oxc-project#206))
- re-enable the wasi build
([oxc-project#193](oxc-project#193))
- use pnpm workspace
([oxc-project#182](oxc-project#182))
- *(deps)* update rust crates
([oxc-project#176](oxc-project#176))
- *(napi)* update NAPI-RS cli version and binding template
([oxc-project#111](oxc-project#111))
- update project github url
- *(deps)* update pnpm to v8.14.1
([oxc-project#52](oxc-project#52))
- *(deps)* update pnpm to v8.14.0
([oxc-project#48](oxc-project#48))
- *(deps)* update pnpm to v8.13.1
([oxc-project#42](oxc-project#42))
- remove FIXME comments
- *(napi)* align `*Fields` user options with enhanced-resolve
([oxc-project#35](oxc-project#35))
- *(deps)* update pnpm to v8.12.1
([oxc-project#21](oxc-project#21))
- add some doc for napi TsconfigOptions
([oxc-project#20](oxc-project#20))
- *(deps)* update pnpm to v8.12.0
([oxc-project#18](oxc-project#18))
- *(README)* adding debugging command from Rspack
- *(deps)* update pnpm to v8.11.0
([oxc-project#9](oxc-project#9))
- *(resolver)* remove tracing_subscriber
([#1362](https://github.com/oxc-project/oxc-resolver/pull/1362))
- *(resolver)* improve documentation
([oxc-project#591](oxc-project#591))

### <!-- 8 -->CI

- check for napi .d.index changes
([oxc-project#491](oxc-project#491))
- *(release-napi)* support `riscv64gc-unknown-linux-gnu` and
`s390x-unknown-linux-gnu`
([oxc-project#451](oxc-project#451))
</blockquote>


</p></details>

---
This PR was generated with
[release-plz](https://github.com/release-plz/release-plz/).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Canonicalized path was dropped error

1 participant