Implement Lambda runtime init error reporting#103
Draft
joe4dev wants to merge 2 commits into
Draft
Conversation
…s API Ports the supervisor and events API from PR #41 to enable proper error reporting when a Lambda runtime process exits unexpectedly (e.g. sys.exit() or missing wrapper script), instead of LocalStack timing out with a generic error. - Add LocalStackSupervisor: wraps ProcessSupervisor, detects unexpected runtime-* process exits and emits SendFault(RuntimeExit) events - Add LocalStackEventsAPI: wraps StandaloneEventsAPI, overrides SendFault to forward errors to LocalStack via SendStatus(error, ...) - Wire both into SandboxBuilder via SetEventsAPI / SetSupervisor - Refactor NewCustomInteropServer to accept a pre-created *LocalStackAdapter shared with the events API - Improve SendInitErrorResponse: properly deserialises the payload, includes RequestId, and sends asynchronously (non-blocking) Enables test_lambda_runtime_exit and test_lambda_runtime_wrapper_not_found. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Use *string for the RequestId field in ErrorResponse so that an empty string is serialized (not omitted by omitempty), while nil — used for fault events — stays omitted. Fixes test_lambda_runtime_error snapshot mismatch where requestId: "" was expected but absent. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
When a Lambda runtime exits unexpectedly or throws an error during initialization, LocalStack previously received no callback and would wait until the environment timeout. This PR adds two complementary error-reporting paths so LocalStack immediately receives a structured
ErrorResponseinstead of timing out.Changes
cmd/localstack/supervisor.go— newLocalStackSupervisorwraps the sandbox'sProcessSupervisorand intercepts process termination events on a background goroutine. When aruntime-*process exits and the runtime is not already shutting down intentionally, it constructs aFaultDatawithfatalerror.RuntimeExitand callseventsAPI.SendFault(). An atomicisShuttingDownflag (set onTerminate/Kill, cleared onExec) prevents duplicate fault events during graceful restarts.cmd/localstack/events.go— newLocalStackEventsAPIwrapstelemetry.StandaloneEventsAPIand overridesSendFaultto forward runtime faults to LocalStack as error status callbacks. It embeds therequestIdin the error message and tracks the current invoke ID (thread-safe viasync.RWMutex) for faults that originate outside of an active invocation.cmd/localstack/custom_interop.go— modifiedErrorResponse.RequestIdchanged fromstringto*stringwithomitempty: a pointer-to-empty-string serializes as""(required by LocalStack's init error contract), whilenil(used in fault events) is omitted.NewCustomInteropServernow accepts a pre-created*LocalStackAdapterinstead of constructing one internally, so the adapter is shared with the events API.SendInitErrorResponsenow parses the raw error payload from the runtime, enriches it with the current invoke ID, and asynchronously POSTs the structured response to LocalStack/status/{runtime_id}/errorbefore propagating to the delegate. Falls back to the raw payload if parsing fails.cmd/localstack/main.go— modifiedLocalStackAdapteris created once upfront and passed to bothNewLocalStackEventsAPIandNewCustomInteropServer. The sandbox is configured withSetEventsAPI(lsEventsAPI)andSetSupervisor(localStackSupv). The supervisor's context is cancelled in the existing shutdown func alongside the file watcher.Tests
Covered by the integration tests in localstack/localstack-pro#7293:
test_lambda_runtime_errorsys.exit()called during inittest_lambda_runtime_exitAWS_LAMBDA_EXEC_WRAPPERscripttest_lambda_runtime_wrapper_not_foundRelated
Depends on #101
Closes DEVX-1