Skip to content

Commit 9484cef

Browse files
committed
docs(snapstart): correct the after-restore hook deadline
The hook's bound was documented as the function timeout. It isn't: Lambda allows the whole Restore phase 10 seconds — runtime load, the after-restore hook, and the readiness check that follows it all share that window — and overrunning it fails the restore with Lambda.SnapStartTimeoutException however long the function timeout is. Behavior is unchanged (the adapter still sets no deadline of its own, since it cannot know its share of the window), but a reader budgeting a slow drain against the wrong number would have been surprised at restore time. Also notes that an AWS_LWA_READINESS_CHECK_TIMEOUT_SECONDS above 10s cannot take effect on a restore, since Lambda times the phase out first.
1 parent bd3bf3b commit 9484cef

4 files changed

Lines changed: 18 additions & 10 deletions

File tree

‎CHANGELOG.md‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@
77
(before checkpoint) and `AWS_LWA_SNAPSTART_AFTER_RESTORE_PATH` (after restore) —
88
so it can drain and re-establish connections. A non-2xx response or a connection
99
failure fails the corresponding SnapStart phase; the adapter sets no deadline of its
10-
own, and the after-restore hook must complete within your function timeout. After
10+
own, and the after-restore hook must complete within Lambda's 10-second `Restore`
11+
phase limit (which it shares with the readiness check that follows it). After
1112
restore the adapter refreshes its own HTTP client and re-runs the readiness check
1213
before admitting traffic, and it rejects external traffic to the hook paths with 403.
1314
- The crate now stops publishing to crates.io (`publish = false`): Lambda Web

‎README.md‎

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -96,15 +96,20 @@ Each hook is an empty `POST`; your application must respond with a `2xx` status.
9696
A non-`2xx` response or a connection failure fails the SnapStart phase
9797
(initialization for the before-checkpoint hook, restore for the after-restore hook)
9898
instead of serving traffic against an improperly prepared application. The adapter
99-
does not impose its own deadline on a hook — Lambda bounds both phases, and the
100-
after-restore hook in particular must finish within your function timeout.
99+
does not impose its own deadline on a hook — Lambda bounds both phases. Note that
100+
Lambda allows the whole `Restore` phase only
101+
[10 seconds](https://docs.aws.amazon.com/lambda/latest/dg/snapstart-troubleshooting.html),
102+
not your function timeout: the after-restore hook and the readiness check that follows
103+
it share that window, and overrunning it fails the restore with
104+
`Lambda.SnapStartTimeoutException`.
101105

102106
After restore, the adapter also automatically refreshes its own HTTP connection
103107
to your application, so it never reuses a connection captured in the snapshot, and
104108
then re-runs the readiness check before admitting traffic. By default this wait is
105109
unbounded; set `AWS_LWA_READINESS_CHECK_TIMEOUT_SECONDS` (fractional seconds allowed)
106110
to bound it, in which case a restore whose application does not report ready within
107-
that timeout fails.
111+
that timeout fails. A value above the 10-second `Restore` limit cannot take effect on
112+
a restore — Lambda times the phase out first.
108113

109114
> These hook paths are control-plane operations. External requests (via API
110115
> Gateway or ALB) that target a configured hook path receive `403 Forbidden` and

‎docs/guide/src/features/snapstart.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ The adapter always registers for the SnapStart lifecycle; the Lambda runtime inv
2121

2222
> **Note:** `AWS_LWA_ASYNC_INIT` is ignored under SnapStart (and under Provisioned Concurrency). It works around the short initialization limit for on-demand cold starts by reporting init complete before the application is ready; neither of those environments has that limit, and finishing early would snapshot — or serve — a half-initialized application. The adapter logs a warning when it ignores the setting.
2323
24-
Each hook is an empty `POST`, and your application must respond with a `2xx` status. A non-`2xx` response or a connection failure fails the SnapStart phase — initialization for the before-checkpoint hook, restore for the after-restore hook — rather than serving traffic against an improperly prepared application. The adapter does not impose its own deadline on a hook: Lambda already bounds both phases, and the after-restore hook in particular must complete within your function timeout, so keep that in mind when a hook does slow work such as draining a large connection pool. The final readiness check runs on every restore (whether or not an after-restore path is configured). By default this readiness wait is unbounded; set `AWS_LWA_READINESS_CHECK_TIMEOUT_SECONDS` (fractional seconds allowed, e.g. `0.5`) to bound it, in which case a restore whose application does not report ready within that timeout fails. The same variable also bounds the initial cold-start readiness check, which under SnapStart is what guarantees the application is ready before the snapshot: when set and the application does not report ready within the timeout, initialization fails (the Lambda runtime never starts) rather than snapshotting or serving an app that never came up.
24+
Each hook is an empty `POST`, and your application must respond with a `2xx` status. A non-`2xx` response or a connection failure fails the SnapStart phase — initialization for the before-checkpoint hook, restore for the after-restore hook — rather than serving traffic against an improperly prepared application. The adapter does not impose its own deadline on a hook: Lambda already bounds both phases. The bound on the after-restore hook is not your function timeout — Lambda allows the whole `Restore` phase only [10 seconds](https://docs.aws.amazon.com/lambda/latest/dg/snapstart-troubleshooting.html), shared by the runtime load, the after-restore hook, and the readiness check that follows it, and overrunning it fails the restore with `Lambda.SnapStartTimeoutException`. Keep that in mind when a hook does slow work such as draining a large connection pool. The final readiness check runs on every restore (whether or not an after-restore path is configured). By default this readiness wait is unbounded; set `AWS_LWA_READINESS_CHECK_TIMEOUT_SECONDS` (fractional seconds allowed, e.g. `0.5`) to bound it, in which case a restore whose application does not report ready within that timeout fails — a value above the 10-second `Restore` limit cannot take effect on a restore, since Lambda times the phase out first. The same variable also bounds the initial cold-start readiness check, which under SnapStart is what guarantees the application is ready before the snapshot: when set and the application does not report ready within the timeout, initialization fails (the Lambda runtime never starts) rather than snapshotting or serving an app that never came up.
2525

2626
## Why you need the hooks
2727

‎src/snapstart.rs‎

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -93,11 +93,13 @@ impl SnapStartHooks {
9393
/// POSTs an empty body to `domain + path`. A non-2xx response or a transport error
9494
/// fails the SnapStart phase.
9595
///
96-
/// Deliberately unbounded: Lambda bounds both phases already (the init budget, and
97-
/// the function timeout for the after-restore hook). A fixed adapter-side cap was
98-
/// unreachable for one phase and killed legitimate slow drains in the other. A cap
99-
/// derived from the function timeout isn't possible — Lambda exposes no timeout
100-
/// env var and there is no invocation context here.
96+
/// Deliberately unbounded: Lambda bounds both phases already — the init budget for
97+
/// before-checkpoint, and the 10-second `Restore` phase limit for after-restore
98+
/// (`Lambda.SnapStartTimeoutException`), which is NOT the function timeout. That
99+
/// 10 seconds also covers runtime load and the readiness check that follows the
100+
/// hook POST, so the adapter cannot know its own share of it; overrunning fails the
101+
/// restore either way. A fixed adapter-side cap was unreachable in one phase and
102+
/// killed legitimate slow drains in the other.
101103
async fn post_hook(client: &Client<HttpConnector, Body>, domain: &Url, path: &str) -> Result<(), Error> {
102104
let mut url = domain.clone();
103105
url.set_path(path);

0 commit comments

Comments
 (0)