-
-
Notifications
You must be signed in to change notification settings - Fork 4.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Fix] Abort Streamer-processing when user-connection aborted #42352
base: master
Are you sure you want to change the base?
[Fix] Abort Streamer-processing when user-connection aborted #42352
Conversation
Signed-off-by: Alexander Brandscheidt <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you 👍
@@ -126,6 +127,7 @@ public function addDirRecursive(string $dir, string $internalDir = ''): void { | |||
/** @var LoggerInterface $logger */ | |||
$logger = \OC::$server->query(LoggerInterface::class); | |||
foreach ($files as $file) { | |||
if(connection_status() !== CONNECTION_NORMAL) return; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if(connection_status() !== CONNECTION_NORMAL) return; | |
if(connection_aborted() === 1) { | |
break; | |
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we can even skip the === 1
:
if(connection_status() !== CONNECTION_NORMAL) return; | |
if (connection_aborted()) { | |
break; | |
} |
Same for the following calls to connection_status
$stream = CallbackWrapper::wrap($stream, | ||
function ($count) use ($stream) { | ||
if (connection_status() !== CONNECTION_NORMAL) { | ||
fclose($stream); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm unsure if closing the stream inside the read callback is a good idea.
I suggested using exceptions to bubble up the state properly here: #8161 (comment)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
mhh, I thought we can handle this gracefully.
The reading system has to check fefo
or if fread
succeeded anyways and can then finalize.
In this case e.g. ZipStreamer doesnt catch exceptions so they just bubble to the top and then after everything finished the file is closed by PHP garbage collection.
On theother hand, graceful handling would let ZipStreamer finalize the Zip stream which is a waste of processing.
If we want an exception (so we force cleanup, if any, to execute) we should be consistent and do this in any other case aswell. What do you think?
@@ -161,6 +163,15 @@ public function addDirRecursive(string $dir, string $internalDir = ''): void { | |||
* @return bool $success | |||
*/ | |||
public function addFileFromStream($stream, string $internalName, int|float $size, $time): bool { | |||
if(connection_status() !== CONNECTION_NORMAL) return false; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if(connection_status() !== CONNECTION_NORMAL) return false; | |
if(connection_aborted() === 1) { | |
return false; | |
} |
Signed-off-by: Alexander Brandscheidt <[email protected]>
@kesselb Hey, some time has passed, sorry if i am bothing you by pinging. |
Summary
Streamer, which builds compressed archives to stream to the browser (e.g. for downloading folders), didnt have checks when the browser aborts the connection (e.g. download cancelled).
This PR adds checks at certain positions:
addDirRecursive
to avoid opening files or further traversing directories, even though writing is impossibleaddFileFromStream
connection_status()
only updates when data is attempted to be send to the browser (e.g. withflush()
)Todo