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

Fix: Coldstart delay #6

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
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
12 changes: 6 additions & 6 deletions app/http.php
Original file line number Diff line number Diff line change
Expand Up @@ -624,16 +624,16 @@ function (string $runtimeId, string $payload, array $variables, int $timeout, st
}

// Ensure runtime started
for ($i = 0; $i < 5; $i++) {
for ($i = 0; $i < 50; $i++) {
if ($activeRuntimes->get($activeRuntimeId)['status'] !== 'pending') {
break;
}

if ($i === 4) {
if ($i === 49) {
throw new Exception('Runtime failed to launch in allocated time.', 500);
}

\sleep(1);
\sleep(0.1);

Choose a reason for hiding this comment

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

Suggested change
\sleep(0.1);
\usleep(100000);

Use usleep if you want to sleep for less than a second. usleep uses microseconds instead, so sleeping for 100000 microseconds is equivalent to sleeping 0.1 seconds.

This also solves the CodeQL failure.

}

// Ensure we have secret
Expand Down Expand Up @@ -696,7 +696,7 @@ function (string $runtimeId, string $payload, array $variables, int $timeout, st
};

// Execute function
for ($i = 0; $i < 5; $i++) {
for ($i = 0; $i < 50; $i++) {
[ 'errNo' => $errNo, 'error' => $error, 'statusCode' => $statusCode, 'executorResponse' => $executorResponse ] = \call_user_func($sendExecuteRequest);

// No error
Expand All @@ -708,11 +708,11 @@ function (string $runtimeId, string $payload, array $variables, int $timeout, st
throw new Exception('An internal curl error has occurred within the executor! Error Msg: ' . $error, 500);
}

if ($i === 4) {
if ($i === 49) {
throw new Exception('An internal curl error has occurred within the executor! Error Msg: ' . $error, 500);
}

\sleep(1);
\sleep(0.1);

Choose a reason for hiding this comment

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

Suggested change
\sleep(0.1);
\usleep(100000);

Same here, use usleep instead.

}

// Extract response
Expand Down