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

   # Which issue does this PR close?
   
   No tracking issue; this is a self-contained correctness fix for two locally
   reproducible native-resource bugs.
   
   # Rationale for this change
   
   1. `OperatorOutputStream.close()` runs `flush()` and then `writer.close()`
      without a finally path. `flush()` can throw from `writeByteRange` (for
      example when a `ThrottleLayer` rate limit rejects the buffered bytes). 
When
      it does, `writer.close()` is skipped, so the native 
`Box<blocking::Writer>`
      is never freed (`NativeObject` has no finalizer) and `isDisposed()` stays
      false, letting later writes go into a broken writer.
   
   2. The listing conversions accumulate JNI local references. In jni 0.22.x a
      plain `JObject` does not delete its local reference on drop; only `Auto` 
or
      `Env::with_local_frame` release them. Every entry built by `intern_list` /
      `make_entries` pins a dozen or more references (plus two per user-metadata
      pair from the map converters) for the entire native call. A directory 
with a
      few hundred entries exhausts a fixed-capacity local reference table, and 
an
      assert-enabled JVM reports `JNI local refs: ... exceeds capacity` under
      `-Xcheck:jni`.
   
   # What changes are included in this PR?
   
   - `OperatorOutputStream.close()` always releases the writer. A `flush()`
     failure is kept as the primary throwable; a failure from `writer.close()` 
is
     attached with `addSuppressed`, so the original flush error is preserved.
     Repeated `close()` calls stay no-ops after disposal.
   - `intern_list` (sync `Operator.list`), `make_entries` (async
     `AsyncOperator.list`), `jmap_to_hashmap` and `hashmap_to_jmap` scope
     per-iteration allocations with `Env::with_local_frame`, so a large listing 
or
     map no longer accumulates local references. The remaining loops in
     `bindings/java/src` either wrap element references in `.auto()` or iterate 
a
     compile-time bounded list.
   - Tests: 
`OperatorInputOutputStreamTest#testOutputStreamCloseReleasesWriterWhenFlushFails`
     and the new `JniLocalRefTest`, which lists 250 entries with user metadata
     through both `Operator.list` and `AsyncOperator.list`.
   
   # Are there any user-facing changes?
   
   No public API change. `close()` now reliably frees the native writer and 
throws
   the original flush error when flushing fails.
   
   # Breaking changes
   
   None.
   
   # AI Usage Statement
   
   - Harness: pi / T3 Code
   - Model: DeepSeek
   - Effort: High
   - Role: Implemented the Java close-path fix, the JNI local-frame changes in
     `intern_list`, `make_entries`, `jmap_to_hashmap` and `hashmap_to_jmap`, and
     the Java tests; reproduced both bugs before the fix and verified the fix 
with
     Rust and Java checks. Assumption: the per-iteration frame capacity values
     (16 for entries, 8 for map reads, 4 for map writes) are sizing hints only 
and
     the JVM grows the frame transparently when needed.
   


-- 
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