mirror of
https://github.com/floci-io/floci.git
synced 2026-12-01 01:12:48 -05:00
fix(lambdaweb): apply a revision's NODE_OPTIONS as AWS does (#6290)
* fix(lambdaweb): let heap flags in NODE_OPTIONS replace the defaults as AWS does AWS drops both of its heap flags when NODE_OPTIONS names --max-old-space-size or --max-semi-space-size, and puts those on the command line in their place. Floci kept its own flags, so a larger heap set in NODE_OPTIONS lost to --max-old-space-size=1024. * test(lambdaweb): copy a quoted heap value from NODE_OPTIONS as AWS does AWS puts --max-old-space-size="1536" on the node command line with its quotes. Node refuses that value, so the start fails with Runtime.ExitError. * docs(lambdaweb): put the NODE_OPTIONS sentences after the require.main one * test(lambdaweb): share the default heap flags in the NODE_OPTIONS tests
This commit is contained in:
1 parent
238d16e541
commit
e7ca14b03b
4 files changed
+90
-6
No files matched your search
+23
-3
@@ -46,6 +46,7 @@ import java.util.zip.ZipEntry;
|
||||
import java.util.zip.ZipOutputStream;
|
||||
|
||||
import static io.restassured.RestAssured.given;
|
||||
import static org.hamcrest.Matchers.contains;
|
||||
import static org.hamcrest.Matchers.endsWith;
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
import static org.hamcrest.Matchers.hasKey;
|
||||
@@ -112,7 +113,8 @@ class LambdaWebDataPlaneDockerIntegrationTest {
|
||||
res.end(JSON.stringify({method: req.method, url: req.url, headers: req.headers, bodyLength: body.length,
|
||||
env: {endpoint: process.env.AWS_LAMBDA_HTTP_ENDPOINT, init: process.env.AWS_LAMBDA_INITIALIZATION_TYPE,
|
||||
exec: process.env.AWS_EXECUTION_ENV, account: process.env.AWS_ACCOUNT_ID,
|
||||
region: process.env.AWS_REGION, custom: process.env.CUSTOM}}));
|
||||
region: process.env.AWS_REGION, custom: process.env.CUSTOM},
|
||||
execArgv: process.execArgv}));
|
||||
});
|
||||
}).listen(Number(port), host);
|
||||
""";
|
||||
@@ -523,6 +525,11 @@ class LambdaWebDataPlaneDockerIntegrationTest {
|
||||
|
||||
private String createFunction(int timeoutSeconds, int maxConcurrencyPerEnvironment, String systemLogLevel,
|
||||
String mode, String authType) throws IOException {
|
||||
return createFunction(timeoutSeconds, maxConcurrencyPerEnvironment, systemLogLevel, mode, authType, null);
|
||||
}
|
||||
|
||||
private String createFunction(int timeoutSeconds, int maxConcurrencyPerEnvironment, String systemLogLevel,
|
||||
String mode, String authType, String nodeOptions) throws IOException {
|
||||
functionName = "dp-docker-" + Long.toString(System.nanoTime(), 36);
|
||||
s3Service.createBucket(BUCKET, "us-east-1");
|
||||
s3Service.putObject(BUCKET, functionName + ".zip", zip(APP), "application/zip", Map.of());
|
||||
@@ -534,12 +541,14 @@ class LambdaWebDataPlaneDockerIntegrationTest {
|
||||
"runtimeConfig": {"runtime": "nodejs24.x"}},
|
||||
"serviceConfig": {"executionRoleArn": "%s", "timeoutSeconds": %d,
|
||||
"maxConcurrencyPerEnvironment": %d,
|
||||
"environmentVariables": {"CUSTOM": "yes", "MODE": "%s"},
|
||||
"environmentVariables": {"CUSTOM": "yes", "MODE": "%s"%s},
|
||||
"telemetryConfig": {"loggingConfig": {"systemLogLevel": "%s"}}}},
|
||||
"endpointConfig": {"endpointName": "dev", "endpointType": "HomeRegion",
|
||||
"authType": "%s", "autoDeploymentMode": "LatestRevision"}}
|
||||
""".formatted(functionName, BUCKET, functionName, ROLE, timeoutSeconds,
|
||||
maxConcurrencyPerEnvironment, mode, systemLogLevel, authType))
|
||||
maxConcurrencyPerEnvironment, mode,
|
||||
nodeOptions == null ? "" : ", \"NODE_OPTIONS\": \"" + nodeOptions + "\"",
|
||||
systemLogLevel, authType))
|
||||
.when().put(BASE + "/web-functions")
|
||||
.then().statusCode(202)
|
||||
.extract().path("endpoint.domainName");
|
||||
@@ -650,6 +659,17 @@ class LambdaWebDataPlaneDockerIntegrationTest {
|
||||
.toList(), events.toString());
|
||||
}
|
||||
|
||||
@Test
|
||||
@Timeout(180)
|
||||
void heapFlagsInNodeOptionsReplaceTheDefaultOnes() throws Exception {
|
||||
String domain = createFunction(30, 64, "INFO", "serve", "ApplicationManaged",
|
||||
"--expose-gc --max-old-space-size=1536");
|
||||
|
||||
given().header("Host", domain).when().get("/").then().statusCode(200)
|
||||
.body("execArgv", contains("--expose-gc", "--max-http-header-size", "135168",
|
||||
"--no-experimental-require-module", "--max-old-space-size=1536"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@Timeout(180)
|
||||
void anAppThatExitsWithAnErrorAtStartGetsTheExitErrorPage() throws Exception {
|
||||
|
||||
+47
@@ -4,14 +4,61 @@ import io.github.hectorvent.floci.services.lambdaweb.LambdaWebEnvironmentManager
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.time.Duration;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
class LambdaWebEnvironmentManagerTest {
|
||||
|
||||
private static final List<String> BASE = List.of("--expose-gc", "--max-http-header-size", "135168",
|
||||
"--no-experimental-require-module");
|
||||
private static final List<String> DEFAULT_HEAP = List.of("--max-semi-space-size=102", "--max-old-space-size=1024");
|
||||
|
||||
@Test
|
||||
void heapFlagsInNodeOptionsReplaceBothDefaultHeapFlags() {
|
||||
assertEquals(flags(DEFAULT_HEAP), LambdaWebEnvironmentManager.nodeFlags(null));
|
||||
assertEquals(flags(List.of("--max-old-space-size=1536")),
|
||||
LambdaWebEnvironmentManager.nodeFlags("--max-old-space-size=1536"));
|
||||
assertEquals(flags(List.of("--max-semi-space-size=64")),
|
||||
LambdaWebEnvironmentManager.nodeFlags("--max-semi-space-size=64"));
|
||||
assertEquals(flags(List.of("--max-old-space-size=1536", "--max-semi-space-size=64")),
|
||||
LambdaWebEnvironmentManager.nodeFlags("--max-old-space-size=1536 --max-semi-space-size=64"));
|
||||
assertEquals(flags(List.of("--max-old-space-size=1536", "--max-old-space-size=1200")),
|
||||
LambdaWebEnvironmentManager.nodeFlags("--max-old-space-size=1536 --max-old-space-size=1200"));
|
||||
assertEquals(flags(List.of("--max_old_space_size=1536")),
|
||||
LambdaWebEnvironmentManager.nodeFlags("--max_old_space_size=1536"));
|
||||
assertEquals(flags(List.of("--max-old_space-size=1536")),
|
||||
LambdaWebEnvironmentManager.nodeFlags("--max-old_space-size=1536"));
|
||||
assertEquals(flags(List.of("--max-old-space-size=1536")),
|
||||
LambdaWebEnvironmentManager.nodeFlags("--expose-gc --max-old-space-size=1536 --title=y"));
|
||||
assertEquals(flags(List.of("--max-semi-space-size=32")),
|
||||
LambdaWebEnvironmentManager.nodeFlags("--expose-gc --max-semi-space-size=32"));
|
||||
assertEquals(flags(List.of("--max-old-space-size")),
|
||||
LambdaWebEnvironmentManager.nodeFlags("--max-old-space-size 1536"));
|
||||
assertEquals(flags(List.of("--max-old-space-size=\"1536\"")),
|
||||
LambdaWebEnvironmentManager.nodeFlags("--max-old-space-size=\"1536\""));
|
||||
}
|
||||
|
||||
@Test
|
||||
void otherFlagsInNodeOptionsKeepTheDefaults() {
|
||||
List<String> defaults = flags(DEFAULT_HEAP);
|
||||
assertEquals(defaults, LambdaWebEnvironmentManager.nodeFlags("--expose-gc"));
|
||||
assertEquals(defaults, LambdaWebEnvironmentManager.nodeFlags("--max-http-header-size=1000"));
|
||||
assertEquals(defaults, LambdaWebEnvironmentManager.nodeFlags("--require ./pre.js"));
|
||||
assertEquals(defaults, LambdaWebEnvironmentManager.nodeFlags("\"--max-old-space-size=1536\""));
|
||||
}
|
||||
|
||||
private static List<String> flags(List<String> heap) {
|
||||
List<String> flags = new ArrayList<>(BASE);
|
||||
flags.addAll(heap);
|
||||
return flags;
|
||||
}
|
||||
|
||||
@Test
|
||||
void onlyAnExitSeenBeforeTheRequestStartedAllowsARetry() {
|
||||
Environment environment = new Environment("pool", "rev-1", "000000000000");
|
||||
|
||||
Reference in new issue
Block a user