From 37d52050f5f3a3534db408dc925972954ed64351 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Mon, 26 Feb 2024 16:54:02 +0100 Subject: [PATCH 1/2] fix(federation): Improve logging Signed-off-by: Joas Schilling --- .../Proxy/TalkV1/Controller/AvatarController.php | 2 +- lib/Federation/Proxy/TalkV1/Controller/ChatController.php | 2 +- lib/Federation/Proxy/TalkV1/ProxyRequest.php | 8 ++++---- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/lib/Federation/Proxy/TalkV1/Controller/AvatarController.php b/lib/Federation/Proxy/TalkV1/Controller/AvatarController.php index 6310f1e9e0b..d9996463763 100644 --- a/lib/Federation/Proxy/TalkV1/Controller/AvatarController.php +++ b/lib/Federation/Proxy/TalkV1/Controller/AvatarController.php @@ -61,7 +61,7 @@ public function getAvatar(Room $room, Participant $participant, bool $darkTheme) ); if ($proxy->getStatusCode() !== Http::STATUS_OK) { - $this->proxy->logUnexpectedStatusCode(__METHOD__, $proxy->getStatusCode()); + $this->proxy->logUnexpectedStatusCode(__METHOD__, $proxy->getStatusCode(), (string) $proxy->getBody()); throw new CannotReachRemoteException('Avatar request had unexpected status code'); } diff --git a/lib/Federation/Proxy/TalkV1/Controller/ChatController.php b/lib/Federation/Proxy/TalkV1/Controller/ChatController.php index 435fb0e0698..3484a4c4842 100644 --- a/lib/Federation/Proxy/TalkV1/Controller/ChatController.php +++ b/lib/Federation/Proxy/TalkV1/Controller/ChatController.php @@ -130,7 +130,7 @@ public function receiveMessages( // FIXME // Poor-mans timeout, should later on cancel/trigger earlier, // when we received a OCM message notifying us about a chat message - sleep($timeout); + sleep(max(0, $timeout - 5)); $proxy = $this->proxy->get( $participant->getAttendee()->getInvitedCloudId(), diff --git a/lib/Federation/Proxy/TalkV1/ProxyRequest.php b/lib/Federation/Proxy/TalkV1/ProxyRequest.php index 070c8b0110e..fee39bd0244 100644 --- a/lib/Federation/Proxy/TalkV1/ProxyRequest.php +++ b/lib/Federation/Proxy/TalkV1/ProxyRequest.php @@ -49,11 +49,11 @@ public function __construct( /** * @return Http::STATUS_BAD_REQUEST */ - public function logUnexpectedStatusCode(string $method, int $statusCode): int { + public function logUnexpectedStatusCode(string $method, int $statusCode, string $logDetails = ''): int { if ($this->config->getSystemValueBool('debug')) { - $this->logger->error('Unexpected status code ' . $statusCode . ' returned for ' . $method); + $this->logger->error('Unexpected status code ' . $statusCode . ' returned for ' . $method . ($logDetails !== '' ? "\n" . $logDetails : '')); } else { - $this->logger->debug('Unexpected status code ' . $statusCode . ' returned for ' . $method); + $this->logger->debug('Unexpected status code ' . $statusCode . ' returned for ' . $method . ($logDetails !== '' ? "\n" . $logDetails : '')); } return Http::STATUS_BAD_REQUEST; } @@ -212,7 +212,7 @@ public function getOCSData(IResponse $response, array $allowedStatusCodes = [Htt throw new \RuntimeException('JSON response is not an array'); } } catch (\Throwable $e) { - $this->logger->error('Error parsing JSON response', ['exception' => $e]); + $this->logger->error('Error parsing JSON response: ' . ($content ?? 'no-data'), ['exception' => $e]); throw new CannotReachRemoteException('Error parsing JSON response', $e->getCode(), $e); } From 028e3c8e1e805971ca02615dd6ce96d0e67b4f16 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Mon, 26 Feb 2024 17:05:52 +0100 Subject: [PATCH 2/2] fix(federation): Add missing protocol Signed-off-by: Joas Schilling --- lib/Federation/Proxy/TalkV1/ProxyRequest.php | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/lib/Federation/Proxy/TalkV1/ProxyRequest.php b/lib/Federation/Proxy/TalkV1/ProxyRequest.php index fee39bd0244..224a952d8c4 100644 --- a/lib/Federation/Proxy/TalkV1/ProxyRequest.php +++ b/lib/Federation/Proxy/TalkV1/ProxyRequest.php @@ -78,6 +78,13 @@ protected function generateDefaultRequestOptions( ]; } + protected function prependProtocolIfNotAvailable(string $url): string { + if (!str_starts_with($url, 'http://') && !str_starts_with($url, 'https://')) { + $url = 'https://' . $url; + } + return $url; + } + /** * @param 'get'|'post'|'put'|'delete' $verb * @throws CannotReachRemoteException @@ -96,7 +103,10 @@ protected function request( } try { - return $this->clientService->newClient()->{$verb}($url, $requestOptions); + return $this->clientService->newClient()->{$verb}( + $this->prependProtocolIfNotAvailable($url), + $requestOptions + ); } catch (ClientException $e) { $status = $e->getResponse()->getStatusCode();