From 7e61bc4ee3a36cb842e3e3b2bfbcdc1f0a541039 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9C=D0=B0=D1=81=D0=BB=D0=BE=D0=B2?= Date: Sun, 22 Nov 2026 20:04:24 +0300 Subject: [PATCH] fix(operations): preserve response processing deadlines and await routed API readiness --- evidence/upload-limit-drain-diagnostic.json | 239 ++++++++++++++++++ .../upload-limit-drain-first-incomplete.json | 7 + infra/tls/gateway.go | 7 +- infra/tls/gateway_test.go | 8 +- scripts/stand.py | 8 +- 5 files changed, 266 insertions(+), 3 deletions(-) create mode 100644 evidence/upload-limit-drain-diagnostic.json create mode 100644 evidence/upload-limit-drain-first-incomplete.json diff --git a/evidence/upload-limit-drain-diagnostic.json b/evidence/upload-limit-drain-diagnostic.json new file mode 100644 index 0000000..cd1250f --- /dev/null +++ b/evidence/upload-limit-drain-diagnostic.json @@ -0,0 +1,239 @@ +{ + "complete": true, + "application_image_revision": "f772237", + "diagnostic_mixed_fleet": true, + "original_haproxy_config_restored": true, + "responses": [ + { + "bytes": 10485761, + "status": 413, + "seconds": 0.21006845899682958, + "instance_id": "3ea617fd06cd4ae6845ab8e3b0684ff3", + "request_id": "07958f9f-c3e3-48b3-9954-e698ead49239" + }, + { + "bytes": 10485761, + "status": 413, + "seconds": 0.13931558400508948, + "instance_id": "1abb5c1742d44b349f3ae49fa287dcfe", + "request_id": "1694744e-7218-4e67-8402-7e3d9a648c2e" + }, + { + "bytes": 10485761, + "status": 413, + "seconds": 0.1400072919932427, + "instance_id": "3ea617fd06cd4ae6845ab8e3b0684ff3", + "request_id": "631e5e3b-d46a-48ee-a36f-32a908a8f13d" + }, + { + "bytes": 10485761, + "status": 413, + "seconds": 0.22844441600318532, + "instance_id": "1abb5c1742d44b349f3ae49fa287dcfe", + "request_id": "43ddd137-3478-46bf-a093-fe32efaaeeae" + }, + { + "bytes": 10485761, + "status": 413, + "seconds": 0.1637733749957988, + "instance_id": "3ea617fd06cd4ae6845ab8e3b0684ff3", + "request_id": "ae094186-0c54-4bfa-826b-172bc1cc4e5c" + }, + { + "bytes": 10485761, + "status": 413, + "seconds": 0.22403962499811314, + "instance_id": "1abb5c1742d44b349f3ae49fa287dcfe", + "request_id": "9c7020db-4b99-4e47-9a2f-315b67484e59" + }, + { + "bytes": 10485761, + "status": 413, + "seconds": 0.2178443330049049, + "instance_id": "3ea617fd06cd4ae6845ab8e3b0684ff3", + "request_id": "a2a60910-5edf-4943-b67a-adcb7297c289" + }, + { + "bytes": 10485761, + "status": 413, + "seconds": 0.1809322500048438, + "instance_id": "1abb5c1742d44b349f3ae49fa287dcfe", + "request_id": "9a073f78-17b8-4a6e-b974-0ffc3a88254f" + }, + { + "bytes": 10485761, + "status": 413, + "seconds": 0.2239770000014687, + "instance_id": "3ea617fd06cd4ae6845ab8e3b0684ff3", + "request_id": "2fabed1c-2274-483e-8e6c-3ef2a59243ef" + }, + { + "bytes": 10485761, + "status": 413, + "seconds": 0.3734959169960348, + "instance_id": "1abb5c1742d44b349f3ae49fa287dcfe", + "request_id": "d3b13f35-e5f6-4198-a1a8-2fea6743100c" + }, + { + "bytes": 10485761, + "status": 413, + "seconds": 0.2877515830041375, + "instance_id": "3ea617fd06cd4ae6845ab8e3b0684ff3", + "request_id": "49af5c28-c0db-485e-8831-278b51e7405f" + }, + { + "bytes": 10485761, + "status": 413, + "seconds": 0.18648466700688004, + "instance_id": "1abb5c1742d44b349f3ae49fa287dcfe", + "request_id": "54cc0b9a-d641-4fb2-a263-d1f38a728e5d" + }, + { + "bytes": 10485761, + "status": 413, + "seconds": 0.22263787500560284, + "instance_id": "3ea617fd06cd4ae6845ab8e3b0684ff3", + "request_id": "a016de1c-1414-4eeb-a202-969cdd2d71e5" + }, + { + "bytes": 10485761, + "status": 413, + "seconds": 0.18420937500195578, + "instance_id": "1abb5c1742d44b349f3ae49fa287dcfe", + "request_id": "197c8903-1f4c-4534-9400-eaa666e33e20" + }, + { + "bytes": 10485761, + "status": 413, + "seconds": 0.21482929099875037, + "instance_id": "3ea617fd06cd4ae6845ab8e3b0684ff3", + "request_id": "6345fcf7-4cdd-4a61-aecd-343650a50778" + }, + { + "bytes": 10485761, + "status": 413, + "seconds": 0.17960895800206345, + "instance_id": "1abb5c1742d44b349f3ae49fa287dcfe", + "request_id": "a7bfe48b-54d9-43c8-a59a-3d39b796fbf0" + }, + { + "bytes": 10485761, + "status": 413, + "seconds": 0.274265165993711, + "instance_id": "3ea617fd06cd4ae6845ab8e3b0684ff3", + "request_id": "04cd774f-bab7-4e7a-9f82-55f68b64739e" + }, + { + "bytes": 10485761, + "status": 413, + "seconds": 0.44748662499478087, + "instance_id": "1abb5c1742d44b349f3ae49fa287dcfe", + "request_id": "68838cbc-03ec-4d1e-9722-e6303604df84" + }, + { + "bytes": 10485761, + "status": 413, + "seconds": 0.2970641669962788, + "instance_id": "3ea617fd06cd4ae6845ab8e3b0684ff3", + "request_id": "24ab5adb-984b-4bc6-b812-c9175d633cc0" + }, + { + "bytes": 10485761, + "status": 413, + "seconds": 0.22560404198884498, + "instance_id": "1abb5c1742d44b349f3ae49fa287dcfe", + "request_id": "f3232954-332a-4e57-8234-f2af614fefa6" + }, + { + "bytes": 10485761, + "status": 413, + "seconds": 0.1671314999985043, + "instance_id": "3ea617fd06cd4ae6845ab8e3b0684ff3", + "request_id": "b5a19642-b1cf-4ac4-a18e-16d1a7623ce8" + }, + { + "bytes": 10485761, + "status": 413, + "seconds": 0.1568706249963725, + "instance_id": "1abb5c1742d44b349f3ae49fa287dcfe", + "request_id": "d4f1b737-5567-4ac7-9f22-b843e45befb9" + }, + { + "bytes": 10485761, + "status": 413, + "seconds": 0.15482391600380652, + "instance_id": "3ea617fd06cd4ae6845ab8e3b0684ff3", + "request_id": "b18b9e47-7f74-4f70-871b-dfaae731c6cf" + }, + { + "bytes": 10485761, + "status": 413, + "seconds": 0.15854324999963865, + "instance_id": "1abb5c1742d44b349f3ae49fa287dcfe", + "request_id": "7390a840-c6fc-46eb-97e5-17a2caf6f0c5" + }, + { + "bytes": 10485761, + "status": 413, + "seconds": 0.140601749997586, + "instance_id": "3ea617fd06cd4ae6845ab8e3b0684ff3", + "request_id": "05eef8f1-0ad1-43a7-9e55-2ceea8b78f4c" + }, + { + "bytes": 10485761, + "status": 413, + "seconds": 0.1621949999971548, + "instance_id": "1abb5c1742d44b349f3ae49fa287dcfe", + "request_id": "fdef608f-21d3-45b6-9a52-9181caa51011" + }, + { + "bytes": 10485761, + "status": 413, + "seconds": 0.1564899160002824, + "instance_id": "3ea617fd06cd4ae6845ab8e3b0684ff3", + "request_id": "1ba86892-8941-41cc-979c-aaff1a2ac857" + }, + { + "bytes": 10485761, + "status": 413, + "seconds": 0.160869957995601, + "instance_id": "1abb5c1742d44b349f3ae49fa287dcfe", + "request_id": "2c6b2168-ea63-4540-bda5-0c3652c61d97" + }, + { + "bytes": 10485761, + "status": 413, + "seconds": 0.34788999999000225, + "instance_id": "3ea617fd06cd4ae6845ab8e3b0684ff3", + "request_id": "2d1941dc-7da6-4331-9ef0-bbb619162124" + }, + { + "bytes": 10485761, + "status": 413, + "seconds": 0.2849016669933917, + "instance_id": "1abb5c1742d44b349f3ae49fa287dcfe", + "request_id": "ad966780-fd3f-4651-8e5a-bdc6bf04bd12" + }, + { + "bytes": 41943040, + "status": 413, + "seconds": 0.7800305830023717, + "instance_id": "3ea617fd06cd4ae6845ab8e3b0684ff3", + "request_id": "2ef4188e-22b0-4294-bd89-8d7d5175d864" + }, + { + "bytes": 41943040, + "status": 413, + "seconds": 0.5988563330029137, + "instance_id": "1abb5c1742d44b349f3ae49fa287dcfe", + "request_id": "672e8945-d0ea-45ae-803b-51e8de672794" + }, + { + "bytes": 41943040, + "status": 413, + "seconds": 0.8117810000112513, + "instance_id": "3ea617fd06cd4ae6845ab8e3b0684ff3", + "request_id": "60bd7802-7d0f-4fb6-9e11-6db65bd61858" + } + ] +} diff --git a/evidence/upload-limit-drain-first-incomplete.json b/evidence/upload-limit-drain-first-incomplete.json new file mode 100644 index 0000000..f7b6492 --- /dev/null +++ b/evidence/upload-limit-drain-first-incomplete.json @@ -0,0 +1,7 @@ +{ + "complete": false, + "application_image_revision": "f772237", + "diagnostic_mixed_fleet": true, + "original_haproxy_config_restored": true, + "responses": [] +} diff --git a/infra/tls/gateway.go b/infra/tls/gateway.go index bf5af69..48905a0 100644 --- a/infra/tls/gateway.go +++ b/infra/tls/gateway.go @@ -365,6 +365,7 @@ type drainingRequestBody struct { mu sync.Mutex once sync.Once deadline func() + reset func() } func (b *drainingRequestBody) Read(data []byte) (int, error) { @@ -376,6 +377,7 @@ func (b *drainingRequestBody) Read(data []byte) (int, error) { func (b *drainingRequestBody) Close() error { b.once.Do(func() { b.deadline() + defer b.reset() b.mu.Lock() defer b.mu.Unlock() // Drain within a short deadline after an early response so closing TLS does @@ -390,9 +392,12 @@ func serveLoopbackProxy(c Config, proxy *httputil.ReverseProxy, w http.ResponseW if c.Role == "api" && r.Body != nil && r.Body != http.NoBody { controller := http.NewResponseController(w) _ = controller.EnableFullDuplex() - _ = controller.SetReadDeadline(time.Now().Add(25 * time.Second)) + receiveDeadline := time.Now().Add(25 * time.Second) + _ = controller.SetReadDeadline(receiveDeadline) body := &drainingRequestBody{ReadCloser: r.Body, deadline: func() { _ = controller.SetReadDeadline(time.Now().Add(2 * time.Second)) + }, reset: func() { + _ = controller.SetReadDeadline(receiveDeadline) }} r.Body = body defer body.Close() diff --git a/infra/tls/gateway_test.go b/infra/tls/gateway_test.go index f1991cb..9498263 100644 --- a/infra/tls/gateway_test.go +++ b/infra/tls/gateway_test.go @@ -51,6 +51,8 @@ func TestEarlyRejectionDoesNotForwardBodyAndAcceptedBodyStillStreams(t *testing. if err != nil { t.Error(err) } + // Request-body cleanup must not cancel legitimate processing. + time.Sleep(2200 * time.Millisecond) w.Write(data) })) defer backend.Close() @@ -75,7 +77,11 @@ func TestEarlyRejectionDoesNotForwardBodyAndAcceptedBodyStillStreams(t *testing. } defer conn.Close() _ = conn.SetDeadline(time.Now().Add(5 * time.Second)) - fmt.Fprintf(conn, "POST / HTTP/1.1\r\nHost: synthetic\r\nConnection: close\r\nContent-Type: image/png\r\nContent-Length: %d\r\n\r\n", len(payload)) + connection := "keep-alive" + if reject { + connection = "close" + } + fmt.Fprintf(conn, "POST / HTTP/1.1\r\nHost: synthetic\r\nConnection: %s\r\nContent-Type: image/png\r\nContent-Length: %d\r\n\r\n", connection, len(payload)) // A load balancer can finish writing before reading the early reply. if _, err := io.WriteString(conn, payload); err != nil { t.Fatal(err) diff --git a/scripts/stand.py b/scripts/stand.py index 94fe8f7..d5eb296 100644 --- a/scripts/stand.py +++ b/scripts/stand.py @@ -106,7 +106,13 @@ def ready(base=BASE, *, timeout=30): while time.monotonic() < end: try: if client.get("/health/ready").status_code == 200: - return + # HAProxy's business and health backends recover separately. + # Check a harmless unauthenticated business route as well. + routed = client.get("/api/v1/users/me") + if routed.status_code == 401 and routed.headers.get( + "x-instance-id" + ): + return except httpx.HTTPError: pass time.sleep(0.2)