mirror of
https://github.com/floci-io/floci.git
synced 2026-12-03 18:18:02 -05:00
feat(lambda): honour the Invoke Qualifier and wait between asynchronous retries as AWS does (#4733)
* feat(lambda): honour the Invoke Qualifier query parameter * feat(lambda): wait between asynchronous retries as AWS does A failed Event invocation now waits floci.services.lambda.async-retry-delay-seconds before its first retry and twice that before its second (default 60, matching AWS), capped at the event's remaining maximum age. The concurrency permit is held only for each attempt, and an emulator reset drops retries still waiting. * test(lambda): prove asynchronous retries end to end * docs(lambda): document asynchronous retry timing and the Invoke Qualifier * fix(lambda): drop retries of deleted functions and tighten async retry edges - Drop a pending asynchronous retry when its function (or version) was deleted. - Decide expiry once, on the injected clock, when a retry is scheduled. - Check the reset generation at routing, so no stale outcome is delivered. - Restore upstream behavior when an attempt throws: stop retrying and route the previous result, or UnknownError when there is none. - Harden tests: in-order permit release, deterministic reset, error types and an unqualified-ARN Qualifier case for Invoke. * fix(lambda): drop a deleted function's pending events on every path Replace the store lookup with a per-function deletion counter, captured when the event is invoked and checked wherever an event is attempted or routed. This covers the expiry path, which bypassed the old check, and a delete-and-recreate of the same name during the wait, which the lookup could not see. Verified against AWS that DeleteFunction drops pending retries without delivering a record. * fix(lambda): clear deletion counts before bumping the reset generation An invoke between the two statements of clear() captured the new generation with a stale deletion count and its event was dropped. The expiry-path deletion test now drops inside the first attempt, so it no longer races the one-second maximum event age. * fix(lambda): keep deletion counts across a reset Clearing them while the old generation was still current let a deleted function's pending event see a zero count and be routed. A reset now only bumps the generation, in one atomic step. * fix(lambda): drop an Event invoke that races DeleteFunction An Event invoke that resolved the function just before a concurrent DeleteFunction could take its deletion-count snapshot after the delete had already moved the count. The event then never looked stale, so the deleted function could still be started and a failure record could still reach its destination. DeleteFunction now moves the deletion count only after the function has left the store, and an Event invoke checks that the function is still in the store after it takes its snapshot and before it queues the event. Either the check sees the function gone and the invoke answers 202 without queueing anything, or the snapshot predates the count change and the event is dropped as stale later. * fix(lambda): validate the Invoke Qualifier query parameter Invoke treated an empty or blank Qualifier as if none had been given and ran $LATEST, and it passed a qualifier longer than 128 characters on to the lookup, which answered 404. AWS rejects both with a 400. A supplied Qualifier must now be 1 to 128 characters of letters, digits, $, _ and -, or Invoke fails with ValidationException. The controller reads the parameter from the raw query, because @QueryParam reports a present but empty value as null and the check could not see it. * fix(lambda): stop pending events before a delete or reset removes state DeleteFunction moved a function's deletion count only after it had removed the function's code and store entry. A retry whose timer fired in that gap still passed the staleness check, tried to start a function with no code, and could deliver a failure record to its destination. An attempt that finished in that gap could deliver its OnFailure record. DeleteFunction now moves the count before it deletes anything, which stops every queued or running event, and again after the store entry is gone, which stops an Event invoke that read the count in between. An emulator reset wiped storage before the executor's clear() moved the reset generation, so a retry firing during the wipe could run or deliver against half-cleared state. The executor now also moves the generation in beforeReset(), which runs before the wipe. clear() still moves it, to drop events accepted between the two. * test(lambda): fix a doc comment and name the tolerated Docker ping failure The class comment now reads "wait as they do on AWS". The Docker ping check names its caught exception "expected" and says why returning false is safe: the test is then skipped rather than failed. * fix(lambda): count version and alias invokes against the function's reservation Routing the Invoke Qualifier to a published version meant a qualified invoke took its permit against the version's snapshot, which carries no reservation, so a reserved concurrency of 0 on the function no longer throttled it and a positive one stopped counting those invokes. The name-qualified path (fn:1, fn:alias) already had the same gap. Reserved concurrency is function-wide in AWS, so the executor now takes the permit against the function's $LATEST record, which holds the reservation. That covers direct Invoke with a Qualifier, qualified names and ARNs, aliases, event source mappings and asynchronous retries alike. It reads the stored record rather than the limiter's region registry because event source pollers can invoke before LambdaService has rehydrated that registry after a restart. * fix(lambda): drop a deleted function's pending events before draining its containers DeleteFunction drained the warm pool before fencing pending asynchronous events, and draining blocks while idle containers stop. A retry whose timer fired in that window still passed the staleness check and could cold-start a container after the drain, leaving it warm for a function that no longer exists. The fence now goes up first.
This commit is contained in:
1 parent
8a2b998378
commit
fa4d4663a2
16 files changed
+1156
-81
No files matched your search
+20
-13
@@ -77,9 +77,12 @@ subsequent unqualified `GetFunction` responses.
|
||||
|
||||
An asynchronous invocation (`InvocationType: Event`) answers `202` immediately and runs on the background
|
||||
pool. If the invocation fails, it is retried up to `MaximumRetryAttempts` (default: 2, total 3 attempts)
|
||||
unless the event age exceeds `MaximumEventAgeInSeconds` (default: 21600 seconds, 6 hours). In Floci,
|
||||
retries run back to back without the delays of live AWS (which waits roughly one minute and then two) to keep
|
||||
local test runs fast.
|
||||
unless the event age exceeds `MaximumEventAgeInSeconds` (default: 21600 seconds, 6 hours). As in AWS, the
|
||||
first retry waits one minute and the second two. `FLOCI_SERVICES_LAMBDA_ASYNC_RETRY_DELAY_SECONDS` sets the
|
||||
first wait (the second is twice it), and `0` retries back to back for fast local test runs. A wait never runs
|
||||
past `MaximumEventAgeInSeconds`, so an event that expires while waiting is reported then. A retry that finds the
|
||||
function's concurrency in use tries again every second until the event expires, where AWS backs off for up to
|
||||
five minutes. Deleting the function drops its pending retries without delivering a record, as AWS does.
|
||||
|
||||
When retries are exhausted or event age is exceeded:
|
||||
|
||||
@@ -125,8 +128,9 @@ type `Lambda Function Invocation Result - Failure`, a `condition` of `RetriesExh
|
||||
`functionError` member is present only on a failure record. The `approximateInvokeCount` field reflects
|
||||
the actual number of attempts executed before completion or exhaustion.
|
||||
|
||||
An alias-specific destination configuration is used when the alias is invoked. If the alias has
|
||||
none, Floci checks the configuration on the version that the alias resolves to.
|
||||
An alias-specific destination configuration is used when the alias is invoked, whether the alias is named
|
||||
in `Qualifier` or on the function name. If the alias has none, Floci checks the configuration on the
|
||||
version that the alias resolves to.
|
||||
|
||||
Two limits are worth knowing:
|
||||
|
||||
@@ -257,14 +261,16 @@ disabled fails with Lambda's error as the resource status reason.
|
||||
| Path on host required | No | Yes |
|
||||
|
||||
!!! note "Concurrency enforcement"
|
||||
Reserved concurrency is enforced: invocations beyond the reserved value
|
||||
return `TooManyRequestsException` (HTTP 429). Functions without a reserved
|
||||
value share a **per-region** pool. AWS Lambda's "account-level" limit is
|
||||
in fact a per-account-per-region quota, and Floci mirrors that by
|
||||
partitioning counters on the ARN's region segment. The pool size (default
|
||||
1000) is configurable via `floci.services.lambda.region-concurrency-limit`
|
||||
and applies independently to each region. `PutFunctionConcurrency`
|
||||
validates that the requested value leaves at least
|
||||
Reserved concurrency is enforced function-wide: invocations of every
|
||||
version and alias count against the function's reservation, and
|
||||
invocations beyond the reserved value return `TooManyRequestsException`
|
||||
(HTTP 429). Functions without a reserved value share a **per-region**
|
||||
pool. AWS Lambda's "account-level" limit is in fact a
|
||||
per-account-per-region quota, and Floci mirrors that by partitioning
|
||||
counters on the ARN's region segment. The pool size (default 1000) is
|
||||
configurable via `floci.services.lambda.region-concurrency-limit` and
|
||||
applies independently to each region. `PutFunctionConcurrency` validates
|
||||
that the requested value leaves at least
|
||||
`floci.services.lambda.unreserved-concurrency-min` (default 100) available
|
||||
for unreserved functions in that region. `PutProvisionedConcurrencyConfig`
|
||||
and related provisioned-concurrency operations remain unimplemented.
|
||||
@@ -367,6 +373,7 @@ These AWS Lambda operations have no handler in Floci. Calls will return `404` or
|
||||
| `FLOCI_SERVICES_LAMBDA_RUNTIME_API_MAX_PORT` | `12499` | Last port in the Lambda Runtime API range. One port is held per running container, so the range width caps concurrent executions. Each running container also holds two Docker connections, so a wider range needs a matching `FLOCI_DOCKER_MAX_CONNECTIONS` |
|
||||
| `FLOCI_SERVICES_LAMBDA_CODE_PATH` | `./data/lambda-code` | Directory where Lambda ZIP files are stored |
|
||||
| `FLOCI_SERVICES_LAMBDA_POLL_INTERVAL_MS` | `1000` | Event-source mapping poll interval (milliseconds) |
|
||||
| `FLOCI_SERVICES_LAMBDA_ASYNC_RETRY_DELAY_SECONDS` | `60` | Wait before the first retry of a failed asynchronous invocation (seconds); the second waits twice this, `0` retries back to back |
|
||||
| `FLOCI_SERVICES_LAMBDA_CONTAINER_IDLE_TIMEOUT_SECONDS` | `300` | Idle container shutdown timeout (seconds) |
|
||||
| `FLOCI_SERVICES_LAMBDA_REGION_CONCURRENCY_LIMIT` | `1000` | Maximum concurrent executions per region |
|
||||
| `FLOCI_SERVICES_LAMBDA_UNRESERVED_CONCURRENCY_MIN` | `100` | Minimum unreserved capacity `PutFunctionConcurrency` must leave |
|
||||
|
||||
Reference in new issue
Block a user