LuciferYang opened a new pull request, #3814:
URL: https://github.com/apache/celeborn/pull/3814
Fixes #3813
### Root cause
`tryWithResources` declares its resource parameter by-name (`f: => R`) and
referenced it twice: `val res = f` evaluates the caller's expression once, then
`func(f)` evaluated it a *second* time. The instance handed to `func` was
therefore never the one closed in `finally` — one leaked resource per call, and
non-idempotent expressions (e.g. `new FileInputStream(file)`) executed twice.
### Change
- `Utils.scala`: pass the already-evaluated `res` to `func` (one line).
Behavior on the other paths (expression throws, expression returns null, `func`
throws) is unchanged or strictly safer.
- `UtilsSuite`: guard test covering both halves of the helper's contract —
- happy path: the expression evaluates exactly once and the instance
received by the function body is the one closed;
- exception path: when `func` throws, `finally` still closes that same
instance.
### Test verification
- Against the unfixed tree the first two assertions fail (`2 did not equal
1`, `received.closed == false`); with the fix the suite passes.
- `mvn -pl common -am test`: all pass except two pre-existing
`CelebornConfSuite` failures that hardcode `EPOLL` and only reproduce on macOS
(unrelated to this change; a companion branch
`test-celebornconf-suite-platform-io-mode` on my fork fixes those).
- `mvn spotless:check -pl common`: pass.
### Impact
Current callers are the two CLI config/version readers (each opened its file
twice per call and leaked one handle). The utility is public shared API in
`common`, so any caller with a non-idempotent resource expression would have
paid double side effects.
--
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]