fix(RemoteService): remove redundant stream cleanup in convertFileTo()#5755
fix(RemoteService): remove redundant stream cleanup in convertFileTo()#5755nicfab wants to merge 1 commit into
Conversation
|
Thanks a lot for creating this pull request! Your contribution means a lot. :) That said, the psalm failure brings up a good point: Even though TL;DR: I am wondering if we can just remove the try/finally altogether and just do return $this->convertTo($file->getName(), $stream, $format, [], $timeout);What do you think @nicfab and @juliusknorr? |
07e4281 to
747e877
Compare
Thanks a lot for the review and the kind words! You're right on both counts: psalm's complaint is legitimate given the type narrowing (the I've updated the PR accordingly: dropped the try/finally and the method now returns the conversion result directly. |
747e877 to
1e98fac
Compare
The raw stream is handed to the Guzzle-based HTTP client as the request body; Guzzle wraps it in a PSR-7 stream and closes the underlying resource once the request has been sent. The fclose() call in the finally block therefore always operates on an invalid resource and logs a warning on every conversion (e.g. one per generated preview). Drop the try/finally block and rely on the HTTP client to close the stream, as suggested in review. Fixes nextcloud#5743 Signed-off-by: Nicola Fabiano <nicola@nicfab.eu>
1e98fac to
e8afb04
Compare
Thanks for the heads-up! Rebased on top of the latest |
Summary
Fixes #5743
convertFileTo()opens a raw stream and passes it toconvertTo(), which hands it to the Guzzle-based HTTP client as the multipart request body. Guzzle wraps it in a PSR-7 stream and closes the underlying resource once the request has been sent. By the time thefinallyblock runs, the resource is no longer valid, sofclose()logs a warning on every conversion — one per generated preview/thumbnail.Since Guzzle takes ownership of the stream and
convertTo()already handles request errors, this PR drops the redundant try/finally block entirely and returns the conversion result directly, as discussed in the review below.Testing
The removal of the explicit cleanup has been discussed in the review; the original symptom and its diagnosis were validated independently by multiple users in #5743 on different stacks (Nextcloud 32/33, richdocuments 9.1/10.2, MariaDB/PostgreSQL, Ubuntu/Debian, Collabora 25.x/26.x): conversions and previews keep working as expected and the warning is no longer logged.