From 987a24f3d3f9f5e3f374f80e8742ad8b6bfae598 Mon Sep 17 00:00:00 2001 From: Gabriele Battimelli Date: Wed, 8 Jul 2026 00:19:28 +0200 Subject: [PATCH] Enable TCP keepalives to survive the long jixia analysis phase The 'Load jixia data into PostgreSQL' step failed with: psycopg.OperationalError: consuming input failed: server closed the connection unexpectedly The DB connection is opened before the jixia analysis phase, which runs 30-60+ min of pure CPU work with zero DB traffic. GitHub Actions runners sit behind Azure's outbound NAT, whose default idle timeout (~4 min) silently drops the connection's NAT mapping long before analysis finishes, so the first write after that fails. Enable TCP keepalives (idle=30s, interval=10s, count=5) so the OS sends probe packets during the idle phase and the NAT mapping never expires. --- database/__init__.py | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/database/__init__.py b/database/__init__.py index b3af96e..27f89e8 100644 --- a/database/__init__.py +++ b/database/__init__.py @@ -42,7 +42,18 @@ def main(): args = parser.parse_args() - with psycopg.connect(os.environ["CONNECTION_STRING"], autocommit=True) as conn: + # The jixia analysis phase can run 30-60+ min with no DB traffic at all. + # GitHub Actions runners sit behind Azure's outbound NAT, whose default + # idle timeout (~4 min) silently drops the connection before that phase + # ends. TCP keepalives (well under 4 min) keep the NAT mapping alive. + with psycopg.connect( + os.environ["CONNECTION_STRING"], + autocommit=True, + keepalives=1, + keepalives_idle=30, + keepalives_interval=10, + keepalives_count=5, + ) as conn: if args.command == "schema": create_schema(conn) elif args.command == "jixia":