Ministack: Free, open-source local AWS emulator - 60+ services, Terraform compatible, real databases. Free forever. MIT licensed.
Python awsaws-emulatoraws-localaws-sdkdevtoolsdockerdynamodbec2emulatorlambdalocalstacklocalstack-alternativeministackmock-awsopen-sourcepythons3sqsterraform
fix(http2): raise keep_alive_max_requests so a connection is not cut after 1000 requests (#2472)
Jeff Hellere56413cf4199
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex b9365c7c..adb63e97 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -11,6 +11,7 @@ Versioning follows [Semantic Versioning](https://semver.org/).- **Aurora DSQL — `AWS IAM GRANT` and `AWS IAM REVOKE`** — with `DSQL_STRICT=1` both were a syntax error, so a migration that maps a Postgres role to an IAM role stopped there. Sent on their own over the simple query protocol (psql, psycopg2), a GRANT maps one or more ARNs to a role and a REVOKE unmaps them; the mappings read back through `sys.iam_pg_role_mappings` with DSQL's six columns and types, a rollback undoes a GRANT, and a GRANT after other DDL in the same transaction answers DSQL's `0A000`. Re-granting raises DSQL's NOTICE and revoking a missing mapping its WARNING; an unknown role answers `42704`, a value that is not an ARN `0P000`, and granting the signed-in role to itself `42501`. Contributed by @toby6578.### Fixed+- **HTTP/2 — a connection is no longer cut after 1000 requests** — Hypercorn's default `keep_alive_max_requests` (1000) sent GOAWAY on an HTTP/2 connection's 1001st request and dropped its response, so a client that keeps one connection (Node's undici, gRPC) lost one request in every thousand (undici: `other side closed`). AWS closes client connections by keepalive duration, not request count; the limit is now 10,000,000, more than one connection sends in AWS's default hour.- **Step Functions — `aws-sdk:scheduler` tasks** — a Task with `arn:aws:states:::aws-sdk:scheduler:<action>` failed with `States.Runtime` ("Service 'scheduler' is not supported in MiniStack aws-sdk integrations"). `createSchedule`, `getSchedule`, `updateSchedule`, `deleteSchedule`, `listSchedules`, `createScheduleGroup`, `getScheduleGroup`, `deleteScheduleGroup` and `listScheduleGroups` now call EventBridge Scheduler in the execution's account and region, as on AWS. The output keeps Scheduler's member names, timestamps are ISO-8601 UTC strings, `StartDate`/`EndDate` are read from ISO-8601 strings with `Z` or a `+hh:mm` offset (cut to milliseconds), `listSchedules` filters by `GroupName`, `NamePrefix` and `State`, and a JSON object or array given as `Target.Input` is sent as compact JSON text. A failed call reports `Scheduler.<ErrorCode>` with the cause suffix `(Service: Scheduler, Status Code: <status>, Request ID: <id>) (SDK Attempt Count: 1)`. Contributed by @kharabasz.- **EventBridge Scheduler — schedule error messages** — `GetSchedule`, `UpdateSchedule` and `DeleteSchedule` for a missing schedule now answer `Schedule <name> does not exist.`, and a duplicate `CreateSchedule` answers `Schedule <name> already exists.`, as on AWS; the messages no longer name the group. Contributed by @kharabasz.- **RDS — Aurora cluster Performance Insights inheritance** — explicit cluster PI settings now round-trip through create/modify/describe and propagate to existing and future members. Instance-managed clusters retain their independent settings until an explicit cluster handoff. Enabled responses include the retention and PI KMS key; cluster disablement survives removal of all members.diff --git a/ministack/app.py b/ministack/app.pyindex ca5a9255..d78ebd11 100644--- a/ministack/app.py+++ b/ministack/app.py@@ -4023,6 +4023,9 @@ def main():config = HypercornConfig()config.bind = [f"{bind_host}:{port}"]config.keep_alive_timeout = 75+ # AWS closes client connections by keepalive duration, not request count; Hypercorn's default of 1000 drops the+ # HTTP/2 request that passes it. 10M is more than one connection can send here in AWS's default hour.+ config.keep_alive_max_requests = 10_000_000config.loglevel = LOG_LEVEL.upper()# USE_SSL=1 enables HTTPS — matches the behaviour previously provideddiff --git a/tests/test_alb.py b/tests/test_alb.pyindex 12bc5710..6a2a3294 100644--- a/tests/test_alb.py+++ b/tests/test_alb.py@@ -908,6 +908,44 @@ def test_elbv2_dataplane_forward_ip_target(elbv2):_alb_http_target_teardown(elbv2, lb_arn, tg_arn, l_arn)+def test_elbv2_dataplane_http2_connection_answers_past_a_thousand_requests(elbv2):+ """One HTTP/2 connection keeps answering past Hypercorn's default keep_alive_max_requests (1000): AWS closes a client+ connection by keepalive duration, not by request count."""+ import socket++ import h2.connection+ import h2.events++ lb_name = "dp-alb-h2"+ lb_arn, tg_arn, l_arn = _alb_http_target_setup(elbv2, lb_name, "127.0.0.1", _SERVER_GATEWAY_PORT)+ parsed = urlparse(_endpoint)+ sock = socket.create_connection((parsed.hostname, parsed.port or 4566), timeout=10)+ try:+ client = h2.connection.H2Connection()+ client.initiate_connection()+ sock.sendall(client.data_to_send())+ for _ in range(1100):+ stream_id = client.get_next_available_stream_id()+ client.send_headers(stream_id, [(":method", "GET"), (":path", f"/_alb/{lb_name}/_ministack/health"),+ (":authority", parsed.netloc), (":scheme", "http")], end_stream=True)+ sock.sendall(client.data_to_send())+ ended = False+ while not ended:+ data = sock.recv(65535)+ assert data, f"connection closed at stream {stream_id}"+ for event in client.receive_data(data):+ assert not isinstance(event, h2.events.ConnectionTerminated), f"GOAWAY at stream {stream_id}"+ if isinstance(event, h2.events.DataReceived):+ client.acknowledge_received_data(event.flow_controlled_length, event.stream_id)+ elif isinstance(event, h2.events.StreamEnded) and event.stream_id == stream_id:+ ended = True+ sock.sendall(client.data_to_send())+ finally:+ sock.close()+ _alb_http_target_teardown(elbv2, lb_arn, tg_arn, l_arn)++def _start_echo_server():"""Answer every GET with the request target and headers the target received, as JSON."""import threading