Skip to content

Commit

Permalink
Merge pull request #115 from open-runtimes/fix-curl-errors
Browse files Browse the repository at this point in the history
fix: runtime ready loop
  • Loading branch information
christyjacob4 authored Oct 23, 2024
2 parents da1d249 + 887aaa1 commit 4c98340
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 12 deletions.
11 changes: 8 additions & 3 deletions app/http.php
Original file line number Diff line number Diff line change
Expand Up @@ -965,16 +965,21 @@ function (string $runtimeId, ?string $payload, string $path, string $method, mix
if ($errNo === 0) {
$body = \json_decode($executorResponse, true);

// If the runtime has not yet attempted to start, it will return 500
if ($statusCode >= 500) {
$error = $body['message'];
// Continues to retry logic
} elseif ($statusCode >= 400) {

// If the runtime fails to start, it will return 400, except for 409
// which indicates that the runtime is already being created
} elseif ($statusCode >= 400 && $statusCode !== 409) {
$error = $body['message'];
throw new Exception('An internal curl error has occurred while starting runtime! Error Msg: ' . $error, 500);
} else {
break;
}
} elseif ($errNo !== 111) { // Connection Refused - see https://openswoole.com/docs/swoole-error-code

// Connection refused - see https://openswoole.com/docs/swoole-error-code
} elseif ($errNo !== 111) {
throw new Exception('An internal curl error has occurred while starting runtime! Error Msg: ' . $error, 500);
}

Expand Down
18 changes: 9 additions & 9 deletions tests/ExecutorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -870,14 +870,14 @@ public function testScenarios(string $image, string $entrypoint, string $folder,
public function provideCustomRuntimes(): array
{
return [
[ 'folder' => 'php', 'image' => 'openruntimes/php:v4-8.1', 'entrypoint' => 'index.php', 'buildCommand' => 'composer install', 'startCommand' => 'php src/server.php' ],
[ 'folder' => 'node', 'image' => 'openruntimes/node:v4-18.0', 'entrypoint' => 'index.js', 'buildCommand' => 'npm i', 'startCommand' => 'pm2 start src/server.js --no-daemon' ],
[ 'folder' => 'php', 'image' => 'openruntimes/php:v4-8.1', 'entrypoint' => 'index.php', 'buildCommand' => 'composer install' ],
[ 'folder' => 'node', 'image' => 'openruntimes/node:v4-18.0', 'entrypoint' => 'index.js', 'buildCommand' => 'npm i'],
// [ 'folder' => 'deno', 'image' => 'openruntimes/deno:v4-1.24', 'entrypoint' => 'index.ts', 'buildCommand' => 'deno cache index.ts', 'startCommand' => 'denon start' ],
[ 'folder' => 'python', 'image' => 'openruntimes/python:v4-3.10', 'entrypoint' => 'index.py', 'buildCommand' => 'pip install --no-cache-dir -r requirements.txt', 'startCommand' => 'python3 src/server.py' ],
[ 'folder' => 'ruby', 'image' => 'openruntimes/ruby:v4-3.1', 'entrypoint' => 'index.rb', 'buildCommand' => '', 'startCommand' => 'bundle exec puma -b tcp://0.0.0.0:3000 -e production' ],
[ 'folder' => 'cpp', 'image' => 'openruntimes/cpp:v4-17', 'entrypoint' => 'index.cc', 'buildCommand' => '', 'startCommand' => 'src/function/cpp_runtime' ],
[ 'folder' => 'dart', 'image' => 'openruntimes/dart:v4-2.18', 'entrypoint' => 'lib/index.dart', 'buildCommand' => 'dart pub get', 'startCommand' => 'src/function/server' ],
[ 'folder' => 'dotnet', 'image' => 'openruntimes/dotnet:v4-6.0', 'entrypoint' => 'Index.cs', 'buildCommand' => '', 'startCommand' => 'dotnet src/function/DotNetRuntime.dll' ],
[ 'folder' => 'python', 'image' => 'openruntimes/python:v4-3.10', 'entrypoint' => 'index.py', 'buildCommand' => 'pip install -r requirements.txt'],
[ 'folder' => 'ruby', 'image' => 'openruntimes/ruby:v4-3.1', 'entrypoint' => 'index.rb', 'buildCommand' => ''],
[ 'folder' => 'cpp', 'image' => 'openruntimes/cpp:v4-17', 'entrypoint' => 'index.cc', 'buildCommand' => ''],
[ 'folder' => 'dart', 'image' => 'openruntimes/dart:v4-2.18', 'entrypoint' => 'lib/index.dart', 'buildCommand' => 'dart pub get'],
[ 'folder' => 'dotnet', 'image' => 'openruntimes/dotnet:v4-6.0', 'entrypoint' => 'Index.cs', 'buildCommand' => ''],
// C++, Swift, Kotlin, Java missing on purpose
];
}
Expand All @@ -889,7 +889,7 @@ public function provideCustomRuntimes(): array
*
* @dataProvider provideCustomRuntimes
*/
public function testCustomRuntimes(string $folder, string $image, string $entrypoint, string $buildCommand, string $startCommand): void
public function testCustomRuntimes(string $folder, string $image, string $entrypoint, string $buildCommand): void
{
// Prepare tar.gz files
$output = '';
Expand Down Expand Up @@ -921,7 +921,7 @@ public function testCustomRuntimes(string $folder, string $image, string $entryp
'source' => $path,
'entrypoint' => $entrypoint,
'image' => $image,
'runtimeEntrypoint' => 'cp /tmp/code.tar.gz /mnt/code/code.tar.gz && nohup helpers/start.sh "' . $startCommand . '"',
'runtimeEntrypoint' => 'cp /tmp/code.tar.gz /mnt/code/code.tar.gz && nohup helpers/start.sh helpers/server.sh',
'timeout' => 120,
'variables' => [
'TEST_VARIABLE' => 'Variable secret'
Expand Down

0 comments on commit 4c98340

Please sign in to comment.