From d9f2f1c37bbd1e165440c9cb817c093ba7b385bb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matej=20Ba=C4=8Do?= Date: Sat, 30 Sep 2023 11:54:54 +0200 Subject: [PATCH 1/3] Introduce execution sync timeout --- app/controllers/api/functions.php | 3 ++- app/controllers/general.php | 1 + src/Executor/Executor.php | 7 +++++-- 3 files changed, 8 insertions(+), 3 deletions(-) diff --git a/app/controllers/api/functions.php b/app/controllers/api/functions.php index 2861ae40c3..18a9b06a4e 100644 --- a/app/controllers/api/functions.php +++ b/app/controllers/api/functions.php @@ -1708,7 +1708,8 @@ App::post('/v1/functions/:functionId/executions') path: $path, method: $method, headers: $headers, - runtimeEntrypoint: $command + runtimeEntrypoint: $command, + requestTimeout: 15 ); $headersFiltered = []; diff --git a/app/controllers/general.php b/app/controllers/general.php index b2b3d37471..0e16f35e29 100644 --- a/app/controllers/general.php +++ b/app/controllers/general.php @@ -139,6 +139,7 @@ function router(App $utopia, Database $dbForConsole, SwooleRequest $swooleReques \curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); // \curl_setopt($ch, CURLOPT_HEADER, true); \curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 10); + \curl_setopt($ch, CURLOPT_TIMEOUT, 15); $executionResponse = \curl_exec($ch); $statusCode = \curl_getinfo($ch, CURLINFO_HTTP_CODE); diff --git a/src/Executor/Executor.php b/src/Executor/Executor.php index d81a4048c2..41d283cd09 100644 --- a/src/Executor/Executor.php +++ b/src/Executor/Executor.php @@ -177,6 +177,7 @@ class Executor string $method, array $headers, string $runtimeEntrypoint = null, + int $requestTimeout = null ) { if (empty($headers['host'])) { $headers['host'] = App::getEnv('_APP_DOMAIN', ''); @@ -204,9 +205,11 @@ class Executor // Safety timeout. Executor has timeout, and open runtime has soft timeout. // This one shouldn't really happen, but prevents from unexpected networking behaviours. - $timeout = $timeout + 15; + if($requestTimeout == null) { + $requestTimeout = $timeout + 15; + } - $response = $this->call(self::METHOD_POST, $route, [ 'x-opr-runtime-id' => $runtimeId ], $params, true, $timeout); + $response = $this->call(self::METHOD_POST, $route, [ 'x-opr-runtime-id' => $runtimeId ], $params, true, $requestTimeout); $status = $response['headers']['status-code']; if ($status >= 400) { From 515fec285806c231cb7a2ecc17e964029a0041a1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matej=20Ba=C4=8Do?= Date: Sat, 30 Sep 2023 11:57:15 +0200 Subject: [PATCH 2/3] Linter fix --- src/Executor/Executor.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Executor/Executor.php b/src/Executor/Executor.php index 41d283cd09..4b68cc5233 100644 --- a/src/Executor/Executor.php +++ b/src/Executor/Executor.php @@ -205,7 +205,7 @@ class Executor // Safety timeout. Executor has timeout, and open runtime has soft timeout. // This one shouldn't really happen, but prevents from unexpected networking behaviours. - if($requestTimeout == null) { + if ($requestTimeout == null) { $requestTimeout = $timeout + 15; } From 1502bfef74562039672b9830666691b36cada3b1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matej=20Ba=C4=8Do?= Date: Sat, 30 Sep 2023 17:24:09 +0200 Subject: [PATCH 3/3] Increase timeout --- app/controllers/api/functions.php | 2 +- app/controllers/general.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/app/controllers/api/functions.php b/app/controllers/api/functions.php index 18a9b06a4e..4c41c8bd34 100644 --- a/app/controllers/api/functions.php +++ b/app/controllers/api/functions.php @@ -1709,7 +1709,7 @@ App::post('/v1/functions/:functionId/executions') method: $method, headers: $headers, runtimeEntrypoint: $command, - requestTimeout: 15 + requestTimeout: 30 ); $headersFiltered = []; diff --git a/app/controllers/general.php b/app/controllers/general.php index 0e16f35e29..bc21da50dd 100644 --- a/app/controllers/general.php +++ b/app/controllers/general.php @@ -139,7 +139,7 @@ function router(App $utopia, Database $dbForConsole, SwooleRequest $swooleReques \curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); // \curl_setopt($ch, CURLOPT_HEADER, true); \curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 10); - \curl_setopt($ch, CURLOPT_TIMEOUT, 15); + \curl_setopt($ch, CURLOPT_TIMEOUT, 30); $executionResponse = \curl_exec($ch); $statusCode = \curl_getinfo($ch, CURLINFO_HTTP_CODE);