Skip to content
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

Stop writing data to the output buffer in case the connection is no l… #37219

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions changelog/unreleased/37219
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
Bugfix: Stop writing data to the output buffer when the connection is not alive

Publicly shared video playback is sending a range http request to get the video
content. In cases where the user is seeking to different positions of the video
will result in a pretty high server load because all the video content is sent
to the browser. Without detecting the connection state on server side all data
is put to the output buffer.
With this change the server processes will stop sending data as soon as the
connection is detected as non-active.

https://github.com/owncloud/core/pull/37219
12 changes: 10 additions & 2 deletions lib/private/Files/View.php
Original file line number Diff line number Diff line change
Expand Up @@ -475,6 +475,7 @@ public function readfile($path) {
$size = $this->filesize($path);
while (!\feof($handle)) {
echo \fread($handle, $chunkSize);
$this->checkConnectionStatus();
\flush();
}
return $size;
Expand Down Expand Up @@ -504,10 +505,10 @@ public function readfilePart($path, $from, $to) {
$len = $chunkSize;
}
echo \fread($handle, $len);
$this->checkConnectionStatus();
\flush();
}
$size = \ftell($handle) - $from;
return $size;
return \ftell($handle) - $from;
}

throw new \OCP\Files\UnseekableException('fseek error');
Expand Down Expand Up @@ -2268,4 +2269,11 @@ private function createParentDirectories($filePath) {
public static function setIgnorePartFile($isIgnored) {
self::$ignorePartFile = $isIgnored;
}

private function checkConnectionStatus(): void {
$connectionStatus = \connection_status();
if ($connectionStatus !== 0) {
throw new \RuntimeException("Connection lost. Status: $connectionStatus");
}
}
}
3 changes: 0 additions & 3 deletions lib/private/legacy/files.php
Original file line number Diff line number Diff line change
Expand Up @@ -192,9 +192,6 @@ public static function get($dir, $files, $params = null) {
$l = \OC::$server->getL10N('lib');
/* @phan-suppress-next-line PhanUndeclaredMethod */
$hint = \method_exists($ex, 'getHint') ? $ex->getHint() : '';
if ($event->hasArgument('message')) {
$hint .= ' ' . $event->getArgument('message');
}
\OC_Template::printErrorPage($l->t('File cannot be downloaded'), $hint);
}
}
Expand Down