Xuanwo opened a new pull request, #8867:
URL: https://github.com/apache/opendal/pull/8867
# Which issue does this PR close?
Closes #.
# Rationale for this change
Both bugs let a mistake in JavaScript turn into silent, and in one case
permanent, misbehavior instead of an error. Both were reproduced locally
against a `memory` operator built from this branch's parent commit.
`ConcurrentLimitLayer` passed `permits` and `httpPermits` through `as usize`:
- `new ConcurrentLimitLayer(0)` builds a zero-permit semaphore that never
hands out a permit. Every operation on the resulting operator blocks forever;
`readSync` stops the Node.js event loop (`setTimeout` in the same process never
fires).
- `new ConcurrentLimitLayer(-1)` wraps to `usize::MAX`, so the limit is
silently disabled rather than reported.
`StatOptions`, `ReadOptions`, and `ReaderOptions` parsed `ifModifiedSince`
and `ifUnmodifiedSince` with `.and_then(|v| v.parse::<Timestamp>().ok())`. Any
unparsable value becomes `None`, so `op.readSync(path, { ifModifiedSince:
'not-a-date' })` returned the object body and `op.stat(path, {
ifUnmodifiedSince: new Date().toUTCString() })` succeeded. A caller who
believes they issued a conditional request gets an unconditional one.
# What changes are included in this PR?
`bindings/nodejs/src/layer.rs`
- `ConcurrentLimitLayer` stores `usize` counts, converted once by a
`parse_permits` helper that rejects values `<= 0` and values that do not fit in
`usize` with `Status::InvalidArg`, following the `ThrottleLayer` predicate from
#8833.
- The constructor and the `httpPermits` setter return `Result`, so an
invalid count fails at the point the user writes it instead of at `build()`
time. `build()` no longer casts.
`bindings/nodejs/src/options.rs`
- A `parse_timestamp` helper returns `Status::InvalidArg` with the offending
option name.
- `ReadOptions::try_from` and `ReaderOptions::try_from` use `.transpose()?`.
- `StatOptions` converts with `TryFrom` instead of `From`.
`bindings/nodejs/src/lib.rs`
- `stat` and `stat_sync` propagate the conversion error.
Tests
- `tests/layer.test.mjs`: `ConcurrentLimitLayer` rejects `0` and `-1` for
`permits` and for `httpPermits`, still accepts positive counts, and stays
usable after a rejected setter.
- `tests/options.test.mjs`: `read`, `readSync`, `reader`, `readerSync`,
`stat`, and `statSync` reject an invalid `ifModifiedSince` and
`ifUnmodifiedSince` (`'not-a-date'` and an RFC 2822 `toUTCString()` value),
while a valid ISO 8601 timestamp is forwarded to the service.
I reverted only `bindings/nodejs/src/` to the parent commit and reran the
two suites: 29 of the 72 tests fail, which are exactly the new cases. With the
fix all 72 pass. There is no test that asserts the zero-permit deadlock itself,
because it would hang the runner; the constructor rejection is what protects
against it.
`RetryLayer` and `TimeoutLayer` were checked for the same class of bug and
left alone: `max_times` is `u32` and only widens to `usize`, and a negative
`timeout`/`io_timeout` saturates to a zero duration, which fails loudly rather
than hanging.
# Are there any user-facing changes?
Invalid values now raise instead of being accepted. `new
ConcurrentLimitLayer(0)`, `new ConcurrentLimitLayer(-1)`, `layer.httpPermits =
0`, `layer.httpPermits = -1`, and malformed
`ifModifiedSince`/`ifUnmodifiedSince` values throw an `InvalidArg` error. Valid
input behaves as before. `generated.d.ts` gains the `# Errors` notes for the
constructor and the setter; no signature changes.
# Breaking changes
# AI Usage Statement
- Harness: pi (T3 Code)
- Model: DeepSeek
- Effort: High
- Role: Located both defects, wrote the Rust and JavaScript changes and the
tests, reproduced both bugs on the parent commit, and ran the local
verification listed below. The human author reviewed the diff and remains
responsible for every claim here. The `memory` backend cannot evaluate
conditional read and stat, so the positive timestamp test only proves the
binding forwards a valid value; it does not exercise service-side conditional
semantics.
--
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]