Xuanwo opened a new pull request, #8951:
URL: https://github.com/apache/opendal/pull/8951
# Which issue does this PR close?
<!--
We generally require a GitHub issue to be filed for all bug fixes and
enhancements. You can link an issue to this PR using the GitHub syntax. For
example `Closes #123` indicates that this PR will close issue #123.
-->
# Rationale for this change
Three correctness and resource-management bugs were identified in
`integrations/spring`:
1. **Native `Operator` handle leak on every blocking operation**:
`OpenDALOperationsImpl.write`, `read`, and `delete` called
`asyncOperator.blocking()` without closing the returned `Operator`. Because
`AsyncOperator.blocking()` allocates a fresh owned native `blocking::Operator`
handle and `NativeObject` does not rely on GC finalization, every blocking
operation leaked native memory and runtime references.
2. **Mismatched `@ConditionalOnMissingBean` types in Spring Boot
auto-configurations**:
- `OpenDALAutoConfiguration` guarded both `opendalTemplate` and
`asyncOperator` with `@ConditionalOnMissingBean(OpenDALOperations.class)`
instead of `OpenDALTemplate.class` and `AsyncOperator.class`.
- `OpenDALReactiveAutoConfiguration` guarded `reactiveOpendalTemplate`
with `ReactiveOpenDALOperations.class`, `asyncOperator` with
`OpenDALOperations.class`, and `openDALSerializerFactory` by bean name (`name =
"openDALSerializerFactory"`) instead of type (`OpenDALSerializerFactory.class`).
As a result, user-defined `AsyncOperator`, `OpenDALTemplate`,
`ReactiveOpenDALTemplate`, or custom-named `OpenDALSerializerFactory` beans
caused duplicate bean definitions (`NoUniqueBeanDefinitionException`).
3. **Eager I/O at `Mono` assembly time**: `ReactiveOpenDALOperationsImpl`
passed `asyncOperator.write/read/delete(...)` directly to
`Mono.fromFuture(CompletableFuture)`, triggering serialization and storage I/O
before subscription and replaying the same `CompletableFuture` on
re-subscription or `.retry()` / `.retryWhen(...)`.
# What changes are included in this PR?
- Wrap `asyncOperator.blocking()` in try-with-resources in
`OpenDALOperationsImpl` (`write`, `read`, `delete`) so each native `Operator`
handle is deterministically closed on both normal completion and exception
paths without changing thrown exception types. Also close the blocking
`Operator` in `OpenDALTemplateTest`.
- Fix `@ConditionalOnMissingBean` target types in `OpenDALAutoConfiguration`
(`OpenDALTemplate.class`, `AsyncOperator.class`) and
`OpenDALReactiveAutoConfiguration` (`ReactiveOpenDALTemplate.class`,
`AsyncOperator.class`, `OpenDALSerializerFactory.class`).
- Switch `ReactiveOpenDALOperationsImpl` to the lazy
`Mono.fromFuture(Supplier)` overload so serialization and storage operations
execute per subscription and re-execute on re-subscription and retries.
- Add tests covering blocking `Operator` disposal on success and exceptions
(`OpenDALOperationsImplTest`), custom bean overrides with
`ApplicationContextRunner` (`OpenDALAutoConfigurationTest`,
`OpenDALReactiveAutoConfigurationTest`), and lazy execution, re-subscription,
deferred serialization errors, and non-blocking retry behavior
(`ReactiveOpenDALOperationsImplTest`).
# Are there any user-facing changes?
- User-provided `AsyncOperator`, `OpenDALTemplate`,
`ReactiveOpenDALTemplate`, and `OpenDALSerializerFactory` beans now properly
override the Spring Boot starter auto-configurations.
- `ReactiveOpenDALOperations` `Mono` publishers are now lazy and execute on
subscription rather than at assembly time.
# Breaking changes
# AI Usage Statement
- Harness: pi
- Model: Gemini 4 Neon
- Effort: high
- Role: Independently verified all three `integrations/spring` bugs against
`main`, implemented the fixes, added regression tests covering native handle
closure, Spring Boot conditional bean overrides, and lazy reactive execution,
and verified the changes locally with the Maven package, test, and Spotless
checks.
--
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]