Skip to content

Enable TCP keepalives to survive long jixia analysis phase#16

Merged
Gabrielebattimelli merged 1 commit into
mainfrom
add-agent-skill
Jul 7, 2026
Merged

Enable TCP keepalives to survive long jixia analysis phase#16
Gabrielebattimelli merged 1 commit into
mainfrom
add-agent-skill

Conversation

@Gabrielebattimelli

Copy link
Copy Markdown
Member

Why

With the Heroku secret refreshed and #15 merged, the pipeline got further than ever — jixia processed all 492 modules cleanly — but the Load jixia data into PostgreSQL step then failed on the very first DB write:

psycopg.OperationalError: consuming input failed: server closed the connection unexpectedly

Root cause

The DB connection is opened in main() before dispatching to the jixia command, then load_data runs batch_run_jixia — a purely CPU-bound analysis phase with zero DB traffic — for 30-60+ minutes (confirmed: 48 min this run) before the first INSERT INTO module. GitHub Actions runners sit behind Azure's outbound NAT, whose default idle timeout is ~4 minutes. The NAT mapping for the idle DB connection is silently dropped long before analysis finishes, so the first write after that fails.

What

Enable TCP keepalives on the connection (keepalives_idle=30s, well under Azure's ~4 min timeout) so the OS sends periodic probe packets during the idle analysis phase, keeping the NAT mapping alive for the whole run.

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.
Copilot AI review requested due to automatic review settings July 7, 2026 22:19
@Gabrielebattimelli Gabrielebattimelli merged commit 22df13b into main Jul 7, 2026
1 check passed

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR addresses intermittent PostgreSQL disconnects during the long, CPU-bound jixia analysis phase by enabling TCP keepalive probes on the existing psycopg connection so it stays active through Azure outbound NAT idle timeouts in GitHub Actions.

Changes:

  • Configure psycopg connections in database CLI entrypoint with TCP keepalive settings (keepalives_idle=30, keepalives_interval=10, keepalives_count=5).
  • Add inline rationale explaining the idle-connection/NAT-timeout failure mode and why keepalives prevent it.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants