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:
TATSUNO “Taz” Yasuhiro authored and GitHub committed 2026-10-23 06:43:27 -04:00
1 parent 238d16e541
commit e7ca14b03b
4 files changed
+90 -6

No files matched your search

@@ -47,6 +47,7 @@ import java.time.Instant;
import java.time.ZoneOffset;
import java.time.format.DateTimeFormatter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Comparator;
import java.util.EnumMap;
import java.util.List;
@@ -85,7 +86,8 @@ public class LambdaWebEnvironmentManager implements ContainerTeardown {
static final Duration LISTEN_TIMEOUT = Duration.ofSeconds(9);
static final Duration SUMMARY_PERIOD = Duration.ofSeconds(60);
static final List<String> NODE_FLAGS = List.of("--expose-gc", "--max-http-header-size", "135168",
"--no-experimental-require-module", "--max-semi-space-size=102", "--max-old-space-size=1024");
"--no-experimental-require-module");
static final List<String> HEAP_FLAGS = List.of("--max-semi-space-size=102", "--max-old-space-size=1024");
private static final Logger LOG = Logger.getLogger(LambdaWebEnvironmentManager.class);
private static final DateTimeFormatter LOG_STREAM_DATE =
DateTimeFormatter.ofPattern("yyyy/MM/dd").withZone(ZoneOffset.UTC);
@@ -546,7 +548,7 @@ public class LambdaWebEnvironmentManager implements ContainerTeardown {
fn.functionName + "-" + revision.revisionId + "-" + shortId);
Map<String, String> userEnv = revision.serviceConfig.environmentVariables == null
? Map.of() : revision.serviceConfig.environmentVariables;
List<String> cmd = new ArrayList<>(NODE_FLAGS);
List<String> cmd = nodeFlags(userEnv.get("NODE_OPTIONS"));
cmd.add(RUNTIME_DIR + "/index.js");
Optional<SessionCreds> roleCredentials = executionRoleCredentials.forRole(
revision.serviceConfig.executionRoleArn, accountId, fn.functionName);
@@ -657,6 +659,21 @@ public class LambdaWebEnvironmentManager implements ContainerTeardown {
}
}
/** AWS swaps both of its heap flags for the ones {@code NODE_OPTIONS} names, and keeps its other flags. */
static List<String> nodeFlags(String nodeOptions) {
List<String> heap = nodeOptions == null ? List.of()
: Arrays.stream(nodeOptions.split("\\s+")).filter(LambdaWebEnvironmentManager::isHeapFlag).toList();
List<String> flags = new ArrayList<>(NODE_FLAGS);
flags.addAll(heap.isEmpty() ? HEAP_FLAGS : heap);
return flags;
}
/** AWS reads {@code _} as {@code -}, as V8 does, but not a flag in quotes. */
private static boolean isHeapFlag(String option) {
String name = option.split("=", 2)[0].replace('_', '-');
return name.equals("--max-old-space-size") || name.equals("--max-semi-space-size");
}
private List<String> environment(String accountId, String region, WebFunctionRevision revision,
Map<String, String> userEnv, Optional<SessionCreds> roleCredentials) {
List<String> env = new ArrayList<>();