Xuanwo opened a new pull request, #8752:
URL: https://github.com/apache/opendal/pull/8752

   # Which issue does this PR close?
   
   No issue: found while auditing async `&mut self` methods in the Node.js 
binding.
   
   # Rationale for this change
   
   `Writer` and `Lister` exposed `pub async unsafe fn(&mut self)` methods. 
`napi-rs` cannot enforce Rust's borrow rules across an async call, so 
overlapping promises such as `Promise.all([writer.write(a), writer.write(b)])` 
or `Promise.all([lister.next(), lister.next()])` could run against the same 
`&mut self`. That is undefined behavior and can corrupt the writer or lister 
state.
   
   `Reader` in the same binding already avoids this by storing its inner reader 
in a `tokio::sync::Mutex` and taking `&self`. This change applies the same 
pattern to `Writer` and `Lister`. A search of `bindings/nodejs/src/` found no 
other `pub async unsafe fn`; the remaining `unsafe fn` methods are synchronous 
and covered by napi's runtime borrow checks.
   
   # What changes are included in this PR?
   
   - Wrap `opendal::Writer` and `opendal::Lister` in `tokio::sync::Mutex` and 
expose safe `pub async fn(&self)` methods for `write`, `close`, and `next`.
   - Serialize overlapping calls so writes and lister entries are handled one 
at a time instead of aliasing.
   - Add regression tests for concurrent writer writes followed by `close`, and 
for concurrent `lister.next()` calls returning every entry exactly once.
   - Regenerate `generated.d.ts` for the updated documentation. The 
JavaScript/TypeScript signatures are unchanged.
   
   # Are there any user-facing changes?
   
   Overlapping calls on a `Writer` or `Lister` are now serialized instead of 
racing. The JavaScript and TypeScript API is unchanged; no migration is 
required.
   
   # Breaking changes
   
   # AI Usage Statement
   
   - Harness: pi coding agent
   - Model: group/deepseek
   - Effort: max
   - Role: Audited the Node.js binding for async `&mut self` aliasing, 
implemented the mutex-backed `Writer` and `Lister`, added the concurrency 
regression tests, and ran clippy, formatting, build, example, and behavior 
tests against `OPENDAL_TEST=memory`. Assumption: serializing calls at the 
binding boundary is the intended behavior for these handles; the tests assert 
data integrity rather than a specific interleaving order.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to