Skip to content

Commit 1c9e2eb

Browse files
committed
feat: circuit breaker
1 parent d8a568f commit 1c9e2eb

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

app/http.php

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -454,6 +454,27 @@ function logError(Throwable $error, string $action, ?Logger $logger, Route $rout
454454
$response->end();
455455
}
456456

457+
// Critical executor errors that indicate the machine is unreachable
458+
if (in_array($errNo, [
459+
CURLE_COULDNT_RESOLVE_HOST, // DNS failure - the executor's hostname cannot be resolved, indicating either the executor is completely offline or DNS issues
460+
CURLE_COULDNT_CONNECT, // TCP connection failure - the executor process is not accepting connections, suggesting it's down or blocked by firewall
461+
CURLE_OPERATION_TIMEDOUT // Connection timeout - the executor is not responding at all, indicating it's frozen or network is completely blocked
462+
])) {
463+
$state->save(RESOURCE_EXECUTORS, $hostname, 'offline', 100);
464+
$state->saveAll(RESOURCE_RUNTIMES . $hostname, []);
465+
Console::error("Executor '$hostname' appears to be down (Error $errNo: $error). Removed from state.");
466+
}
467+
// Runtime-specific errors that indicate issues with processing a specific request
468+
// These errors occur after a connection is established, suggesting the executor is up but the runtime is having issues
469+
elseif (!empty($runtimeId) && in_array($errNo, [
470+
CURLE_RECV_ERROR, // Failed to receive response - runtime might have crashed while processing
471+
CURLE_SEND_ERROR, // Failed to send request - runtime might be overloaded or in a bad state
472+
CURLE_GOT_NOTHING // Empty response - runtime likely crashed after accepting the connection
473+
])) {
474+
$state->save(RESOURCE_RUNTIMES . $hostname, $runtimeId, 'fail', 0);
475+
Console::warning("Runtime '$runtimeId' on executor '$hostname' encountered an error (Error $errNo: $error). Removed from state.");
476+
}
477+
457478
throw new Exception('Unexpected curl error between proxy and executor ID ' . $hostname . ' (' . $errNo . '): ' . $error);
458479
}
459480

0 commit comments

Comments
 (0)