mirror of
https://github.com/floci-io/floci.git
synced 2026-11-27 07:39:24 -05:00
fix(lambdaweb): report init failures as AWS does (#5960)
* fix(lambdaweb): tell why a Web Function app failed to start as AWS does An app that exits at start with a status other than 0 now gets Runtime.ExitError, and an app that cannot find a module at import gets Runtime.ImportCodeError. A failed import writes the one ERROR event AWS writes in place of Node's stack. * fix(lambdaweb): read the init error type from a file so any exit status keeps its meaning * fix(lambdaweb): write the init error type where any user can * fix(lambdaweb): clear an init error type left in the runtime image
This commit is contained in:
1 parent
9ceedde585
commit
b6bc3032f1
6 files changed
+99
-6
No files matched your search
+26
-1
@@ -32,6 +32,7 @@ import jakarta.annotation.PreDestroy;
|
||||
import jakarta.enterprise.context.ApplicationScoped;
|
||||
import jakarta.inject.Inject;
|
||||
import org.apache.commons.compress.archivers.tar.TarArchiveEntry;
|
||||
import org.apache.commons.compress.archivers.tar.TarArchiveInputStream;
|
||||
import org.apache.commons.compress.archivers.tar.TarArchiveOutputStream;
|
||||
import org.jboss.logging.Logger;
|
||||
|
||||
@@ -101,6 +102,9 @@ public class LambdaWebEnvironmentManager implements ContainerTeardown {
|
||||
private static final String[] READ_USAGE = {"/bin/cat", "/sys/fs/cgroup/cpu.stat", "/sys/fs/cgroup/memory.peak"};
|
||||
private static final long SIGKILL_STATUS = 137;
|
||||
private static final long SIGTERM_STATUS = 143;
|
||||
/** Where index.mjs writes the error type of an app that fails to load. */
|
||||
private static final String INIT_ERROR_FILE = "/tmp/floci-init-error";
|
||||
private static final int INIT_ERROR_MAX_BYTES = 64;
|
||||
/** Longer than the data plane waits to see an exit, so a request the exit failed is counted. */
|
||||
private static final Duration EXCHANGES_WAIT = Duration.ofSeconds(2);
|
||||
|
||||
@@ -722,7 +726,7 @@ public class LambdaWebEnvironmentManager implements ContainerTeardown {
|
||||
LOG.infov("The Lambda Web environment {0} exited with status {1} before it listened: {2}",
|
||||
containerId, exitCode.get(), lastLogLines(containerId));
|
||||
throw new StartFailure(exitCode.get() == 0
|
||||
? LambdaWebErrorPages.RUNTIME_EXIT : LambdaWebErrorPages.INIT_CODE_ERROR);
|
||||
? LambdaWebErrorPages.RUNTIME_EXIT : initErrorPage(containerId));
|
||||
}
|
||||
if (isListening(containerId)) {
|
||||
return;
|
||||
@@ -743,6 +747,27 @@ public class LambdaWebEnvironmentManager implements ContainerTeardown {
|
||||
}
|
||||
}
|
||||
|
||||
/** The page for an app that ended with an error before it listened. The container has stopped but still exists. */
|
||||
private LambdaWebErrorPages.Page initErrorPage(String containerId) {
|
||||
String errorType = "";
|
||||
try (InputStream archive = lifecycleManager.getDockerClient()
|
||||
.copyArchiveFromContainerCmd(containerId, INIT_ERROR_FILE).exec();
|
||||
TarArchiveInputStream tar = new TarArchiveInputStream(archive)) {
|
||||
if (tar.getNextEntry() != null) {
|
||||
errorType = new String(tar.readNBytes(INIT_ERROR_MAX_BYTES), StandardCharsets.UTF_8);
|
||||
}
|
||||
} catch (NotFoundException expected) {
|
||||
// The app exited on its own, so index.mjs wrote no error type.
|
||||
} catch (IOException | RuntimeException e) {
|
||||
LOG.warnv(e, "Could not read the init error of the Lambda Web environment {0}", containerId);
|
||||
}
|
||||
return switch (errorType) {
|
||||
case "Application.InitCodeError" -> LambdaWebErrorPages.INIT_CODE_ERROR;
|
||||
case "Runtime.ImportCodeError" -> LambdaWebErrorPages.IMPORT_CODE_ERROR;
|
||||
default -> LambdaWebErrorPages.RUNTIME_EXIT_ERROR;
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Probes from inside the container. A published port on Docker Desktop accepts a connection
|
||||
* before anything listens behind it, so a connect from the host proves nothing.
|
||||
|
||||
@@ -28,7 +28,9 @@ final class LambdaWebErrorPages {
|
||||
static final Page TIMEOUT_LISTEN_ERROR = new Page(502, "Bad Gateway", "Application.TimeoutListenError",
|
||||
APPLICATION_ERROR);
|
||||
static final Page INIT_CODE_ERROR = new Page(502, "Bad Gateway", "Application.InitCodeError", APPLICATION_ERROR);
|
||||
static final Page IMPORT_CODE_ERROR = new Page(502, "Bad Gateway", "Runtime.ImportCodeError", APPLICATION_ERROR);
|
||||
static final Page RUNTIME_EXIT = new Page(502, "Bad Gateway", "Runtime.Exit", APPLICATION_ERROR);
|
||||
static final Page RUNTIME_EXIT_ERROR = new Page(502, "Bad Gateway", "Runtime.ExitError", APPLICATION_ERROR);
|
||||
private static final String RATE_EXCEEDED = "Request rate exceeded. Please try again later.";
|
||||
static final Page ENDPOINT_MAX_ENV_THROTTLE = new Page(429, "Too Many Requests",
|
||||
"Platform.EndpointMaxEnvThrottle", RATE_EXCEEDED);
|
||||
|
||||
Reference in new issue
Block a user