fix: pool Hive API connections in a shared keep-alive session - #18
Open
danceratopz wants to merge 1 commit into
Open
fix: pool Hive API connections in a shared keep-alive session#18danceratopz wants to merge 1 commit into
danceratopz wants to merge 1 commit into
Conversation
Replace the bare requests.post/requests.delete calls in HiveTestSuite start/end, HiveTest start/end and register_multi_test_client with a process-wide requests.Session mounting an HTTPAdapter with a urllib3.Retry policy (connect-error retries with exponential backoff). Per-call connections leave a TIME_WAIT socket per request toward the single fixed Hive API endpoint; at consume-enginex throughput (>100 tests/s, three API calls per test) this exhausts the simulator's ephemeral port range toward that endpoint and connect() fails with EADDRNOTAVAIL (Errno 99), sporadically failing and silently dropping tests. Pooling collapses ~3 connections per test into a handful of persistent keep-alive sockets, removing the mechanism. Only connect errors are retried: they are raised before the request is sent, so retrying cannot duplicate a non-idempotent POST.
Draft
2 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Replace the bare
requests.post/requests.deletecalls inHiveTestSuite.start/end,HiveTest.start/endandHiveTest.register_multi_test_clientwith a single process-widerequests.Sessionmounting anHTTPAdapterwith aurllib3.Retrypolicy (connect-error retries with exponential backoff).Why
See recent sporadic fails on the enginex dashboard:
Each bare call opens a fresh TCP connection and leaves the socket in TIME_WAIT for 60 s. Ephemeral-port exhaustion is per destination tuple, and every Hive API call targets the one fixed endpoint, so all churn piles onto a single
(dst_ip, dst_port). Atconsume-enginexthroughput (~110–145 tests/s on the dashboard host × 3 calls/test ≈ 330–440 connections/s) the ~28k-port ephemeral range toward the Hive API fills in ~90 s andconnect()intermittently fails withOSError: [Errno 99](EADDRNOTAVAIL) on all xdist workers at once. In the 2026-07-18/19 nethermindeels/consume-enginexdashboard runs this produced 4–5 spurious "Test was terminated by host" failures and silently dropped 85/40 test results.Pooling collapses ~3 connections/test (~163k per full run) into a few persistent keep-alive sockets — removing the mechanism rather than raising the ceiling.
Retry semantics
Only connect errors are retried (5 attempts, 0.5 s backoff factor, ~15 s total): they are raised before the request is sent, so a retry cannot duplicate a non-idempotent POST (no double
start_test). Read errors and HTTP error statuses are not retried.Keep-alive caveat (verified)
Pooling only helps if the server honors keep-alive. Hive's Go backend serves the sim API with a stock
net/httpserver (internal/libhive/run.go:&http.Server{Handler: tm.API()}) — keep-alives on by default, no idle timeout, no handler emitsConnection: close. Confirmed empirically below.Validation
Hive
--dev+ nethermind 1.40.0-unstable, 12,888consume-enginexCancun tests at-n 4, samplingss -tan state time-wait '( dport = :3000 )':Notes
HiveTestSuite/HiveTestdataclasses unchanged (stillasdict/JSON round-trippable, as execution-specs relies on).urllib3>=1.26.0,<3declared explicitly (>=1.26.0for the modernRetrykwargs;<3congruent withrequests>=2.31.0, and the 2.x line is what CI and execution-specs actually resolve).src/hive/tests/test_session.py) run against a local in-process HTTP server — no hive required: singleton behavior, retry config, 42-calls-over-1-connection reuse, connect-retry until a late-starting server is up.Release
Propose tagging
v0.1.0a6after merge (setuptools-scm; move the CHANGELOG[Unreleased]entry underv0.1.0a6); execution-specs then bumpsethereum-hive>=0.1.0a5,<1.0.0→>=0.1.0a6,<1.0.0.