diff --git a/docs/guides/configuration.md b/docs/guides/configuration.md index fc5f82e9..8b9c23dd 100644 --- a/docs/guides/configuration.md +++ b/docs/guides/configuration.md @@ -79,15 +79,15 @@ builder.Services.ConfigureLambdaHostOptions(options => }); ``` -| Option | Type | Default | Description | -|--------------------------------|--------------------------|------------------------------------|-----------------------------------------------------------------------------| -| `InitTimeout` | `TimeSpan` | 5 seconds | Maximum time all `OnInit` handlers collectively have before cancellation. | -| `InvocationCancellationBuffer` | `TimeSpan` | 3 seconds | Buffer subtracted from remaining time before the invocation token fires. | -| `ShutdownDuration` | `TimeSpan` | `ShutdownDuration.ExternalExtensions` (500 ms) | Expected window between SIGTERM and SIGKILL. | -| `ShutdownDurationBuffer` | `TimeSpan` | 50 ms | Safety margin deducted from `ShutdownDuration` to guarantee cleanup. | -| `ClearLambdaOutputFormatting` | `bool` | `false` | Automatically register the built-in OnInit handler that clears console formatting. | -| `BootstrapHttpClient` | `HttpClient?` | `null` | Custom client for the Lambda bootstrap runtime API. | -| `BootstrapOptions` | `LambdaBootstrapOptions` | `new()` | Low-level runtime bootstrap configuration (timeouts, heartbeats, etc.). | +| Option | Type | Default | Description | +|--------------------------------|--------------------------|-----------------------------------------------|------------------------------------------------------------------------------------| +| `InitTimeout` | `TimeSpan` | 5 seconds | Maximum time all `OnInit` handlers collectively have before cancellation. | +| `InvocationCancellationBuffer` | `TimeSpan` | 500 milliseconds | Buffer subtracted from remaining time before the invocation token fires. | +| `ShutdownDuration` | `TimeSpan` | `ShutdownDuration.ExternalExtensions` (500ms) | Expected window between SIGTERM and SIGKILL. | +| `ShutdownDurationBuffer` | `TimeSpan` | 50ms | Safety margin deducted from `ShutdownDuration` to guarantee cleanup. | +| `ClearLambdaOutputFormatting` | `bool` | `false` | Automatically register the built-in OnInit handler that clears console formatting. | +| `BootstrapHttpClient` | `HttpClient?` | `null` | Custom client for the Lambda bootstrap runtime API. | +| `BootstrapOptions` | `LambdaBootstrapOptions` | `new()` | Low-level runtime bootstrap configuration (timeouts, heartbeats, etc.). | ### `InitTimeout` @@ -142,9 +142,9 @@ lambda.OnShutdown(async (ITelemetry telemetry, CancellationToken ct) => Choose from the provided constants when possible: -- `ShutdownDuration.NoExtensions` – No extensions installed (0 ms window). -- `ShutdownDuration.InternalExtensions` – Only internal extensions (300 ms). -- `ShutdownDuration.ExternalExtensions` – External extension installed (500 ms, default). +- `ShutdownDuration.NoExtensions` – No extensions installed (0ms window). +- `ShutdownDuration.InternalExtensions` – Only internal extensions (300ms). +- `ShutdownDuration.ExternalExtensions` – External extension installed (500ms, default). - Any custom `TimeSpan` when your environment requires more/less time. ### `ClearLambdaOutputFormatting` diff --git a/docs/guides/dependency-injection.md b/docs/guides/dependency-injection.md index 952d9144..726a75d6 100644 --- a/docs/guides/dependency-injection.md +++ b/docs/guides/dependency-injection.md @@ -70,7 +70,7 @@ If your handler doesn't need the Lambda payload, omit the `[Event]` parameter en !!! tip "Cancellation buffers" The cancellation token fires slightly **before** AWS kills the process: - - The runtime subtracts `LambdaHostOptions.InvocationCancellationBuffer` (default 3s) from the + - The runtime subtracts `LambdaHostOptions.InvocationCancellationBuffer` (default 500ms) from the remaining time when creating the token. - Always pass it down to outbound SDK calls and database queries so you can stop work cleanly. @@ -131,12 +131,12 @@ lambda.MapHandler(( ## Host-Specific Pitfalls -| Pitfall | Impact | Fix | -|---------|--------|-----| +| Pitfall | Impact | Fix | +|---------------------------------------|-----------------------------------------------------|-----------------------------------------------------------------------------------------| | Singleton depends on a scoped service | Scoped instance from first invocation leaks forever | Inject `IServiceProvider`, create a scope, resolve the scoped service inside the method | -| Storing scoped services in singletons | `ObjectDisposedException` on later invocations | Keep scoped dependencies scoped; pass data instead of services | -| Over-injecting handlers | Hard-to-test functions with 8+ services | Move orchestration into services; keep handlers thin | -| Forgetting cancellation tokens | Lambda kills the environment mid-work | Always inject `CancellationToken` and pass it down | +| Storing scoped services in singletons | `ObjectDisposedException` on later invocations | Keep scoped dependencies scoped; pass data instead of services | +| Over-injecting handlers | Hard-to-test functions with 8+ services | Move orchestration into services; keep handlers thin | +| Forgetting cancellation tokens | Lambda kills the environment mid-work | Always inject `CancellationToken` and pass it down | ## Key Takeaways diff --git a/src/AwsLambda.Host/Core/Options/LambdaHostOptions.cs b/src/AwsLambda.Host/Core/Options/LambdaHostOptions.cs index 953c05cc..c846a0ae 100644 --- a/src/AwsLambda.Host/Core/Options/LambdaHostOptions.cs +++ b/src/AwsLambda.Host/Core/Options/LambdaHostOptions.cs @@ -55,8 +55,8 @@ public class LambdaHostOptions /// Gets or sets the buffer duration subtracted from the Lambda function's remaining /// invocation time when creating cancellation tokens. /// - /// Default is 3 seconds. - public TimeSpan InvocationCancellationBuffer { get; set; } = TimeSpan.FromSeconds(3); + /// Default is 500 milliseconds. + public TimeSpan InvocationCancellationBuffer { get; set; } = TimeSpan.FromMilliseconds(500); /// /// Gets or sets the duration between when AWS sends SIGTERM and SIGKILL to the Lambda