Skip to content

Commit cb4faf9

Browse files
joe4devclaude
andcommitted
fix(init): read LOCALSTACK_INIT_PHASE_TIMEOUT via InitLsOpts and unset it
Follow the established LocalStack-env strategy: capture the value in InitLsOpts (before UnsetLsEnvs runs) and add it to the UnsetLsEnvs list. Previously it was read inline with os.Getenv after UnsetLsEnvs, so the variable was never unset and leaked into the function's environment (forwarded via os.Environ in InitHandler), breaking AWS parity. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
1 parent a34955c commit cb4faf9

1 file changed

Lines changed: 13 additions & 12 deletions

File tree

cmd/localstack/main.go

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ type LsOpts struct {
4343
EnableXRayTelemetry string
4444
PostInvokeWaitMS string
4545
MaxPayloadSize string
46+
InitPhaseTimeout string
4647
}
4748

4849
func GetEnvOrDie(env string) string {
@@ -60,12 +61,13 @@ func InitLsOpts() *LsOpts {
6061
RuntimeId: GetEnvOrDie("LOCALSTACK_RUNTIME_ID"),
6162
AccountId: GetenvWithDefault("LOCALSTACK_FUNCTION_ACCOUNT_ID", "000000000000"),
6263
// optional with default
63-
InteropPort: GetenvWithDefault("LOCALSTACK_INTEROP_PORT", "9563"),
64-
InitTracingPort: GetenvWithDefault("LOCALSTACK_RUNTIME_TRACING_PORT", "9564"),
65-
User: GetenvWithDefault("LOCALSTACK_USER", "sbx_user1051"),
66-
InitLogLevel: GetenvWithDefault("LOCALSTACK_INIT_LOG_LEVEL", "warn"),
67-
EdgePort: GetenvWithDefault("EDGE_PORT", "4566"),
68-
MaxPayloadSize: GetenvWithDefault("LOCALSTACK_MAX_PAYLOAD_SIZE", "6291556"),
64+
InteropPort: GetenvWithDefault("LOCALSTACK_INTEROP_PORT", "9563"),
65+
InitTracingPort: GetenvWithDefault("LOCALSTACK_RUNTIME_TRACING_PORT", "9564"),
66+
User: GetenvWithDefault("LOCALSTACK_USER", "sbx_user1051"),
67+
InitLogLevel: GetenvWithDefault("LOCALSTACK_INIT_LOG_LEVEL", "warn"),
68+
EdgePort: GetenvWithDefault("EDGE_PORT", "4566"),
69+
MaxPayloadSize: GetenvWithDefault("LOCALSTACK_MAX_PAYLOAD_SIZE", "6291556"),
70+
InitPhaseTimeout: GetenvWithDefault("LOCALSTACK_INIT_PHASE_TIMEOUT", strconv.Itoa(defaultInitPhaseTimeoutSeconds)),
6971
// optional or empty
7072
CodeArchives: os.Getenv("LOCALSTACK_CODE_ARCHIVES"),
7173
HotReloadingPaths: strings.Split(GetenvWithDefault("LOCALSTACK_HOT_RELOADING_PATHS", ""), ","),
@@ -93,6 +95,7 @@ func UnsetLsEnvs() {
9395
"LOCALSTACK_POST_INVOKE_WAIT_MS",
9496
"LOCALSTACK_FUNCTION_ACCOUNT_ID",
9597
"LOCALSTACK_MAX_PAYLOAD_SIZE",
98+
"LOCALSTACK_INIT_PHASE_TIMEOUT",
9699
"LOCALSTACK_CHMOD_PATHS",
97100

98101
// Docker container ID
@@ -271,12 +274,10 @@ func main() {
271274
InitHandler(sandbox.LambdaInvokeAPI(), GetEnvOrDie("AWS_LAMBDA_FUNCTION_VERSION"), int64(invokeTimeoutSeconds), bootstrap, lsOpts.AccountId) // TODO: replace this with a custom init
272275

273276
initPhaseTimeoutSeconds := defaultInitPhaseTimeoutSeconds
274-
if v := os.Getenv("LOCALSTACK_INIT_PHASE_TIMEOUT"); v != "" {
275-
if parsed, perr := strconv.Atoi(v); perr == nil {
276-
initPhaseTimeoutSeconds = parsed
277-
} else {
278-
log.Warnln("Invalid LOCALSTACK_INIT_PHASE_TIMEOUT, using default:", perr)
279-
}
277+
if parsed, perr := strconv.Atoi(lsOpts.InitPhaseTimeout); perr == nil {
278+
initPhaseTimeoutSeconds = parsed
279+
} else {
280+
log.Warnln("Invalid LOCALSTACK_INIT_PHASE_TIMEOUT, using default:", perr)
280281
}
281282

282283
log.Debugln("Awaiting initialization of runtime init.")

0 commit comments

Comments
 (0)