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

Increase timeout if proxy is starting #1269

Merged
merged 2 commits into from
Dec 3, 2020
Merged
Changes from 1 commit
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
29 changes: 29 additions & 0 deletions lib/WOPI/DiscoveryManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,35 @@ public function fetchFromRemote() {
$options['verify'] = false;
}

// first load with proxy can take some time - increase timeout in that case
$usesProxy = false;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would probably be nice to move this into a dedicated function so the general flow is a bit more readable and we might be able to reuse this in case we need it for any other request that might run into the default timeout.

$proxyPos = strrpos($wopiDiscovery, 'proxy.php');
if ($proxyPos === false)
$usesProxy = false;
else
$usesProxy = true;

if ($usesProxy === true) {
$statusUrl = substr($wopiDiscovery, 0, $proxyPos);
$statusUrl = $statusUrl . 'proxy.php?status';

try {
$response = $client->get($statusUrl, $options);

if ($response->getStatusCode() === 200) {
$body = json_decode($response->getBody(), true);

if ($body['status'] === 'starting'
|| $body['status'] === 'stopped'
|| $body['status'] === 'restarting') {
$options['timeout'] = 180;
}
}
} catch (\Exception $e) {
// ignore
}
}

try {
return $client->get($wopiDiscovery, $options);
} catch (\Exception $e) {
Expand Down