Skip to content

[VDR] ERR-8508619d · Connection-level retries are unbounded and silent for the first ~50 seconds #2216

Open

Description

@anwithk

The except ServerDisconnectedError and except ClientOSError branches increment a local retries counter that is never compared against MAX_NUM_TRIES (only the generic except Exception branch at line 259 enforces the cap). A permanently unreachable server therefore loops forever rather than raising. Because DISCONNECTED_CLIENT_OS_PRINT_INTERVAL is 100 and each iteration sleeps 0.5s, the first diagnostic is withheld for ~50s, so the user sees a completely silent hang with no way to tell a slow model from a dead one.

Suggested fix: Apply the MAX_NUM_TRIES cap to all three branches and re-raise the original error once exhausted, with a message naming the URL and the likely cause (server not started / wrong port). Print on the first failure, not every 100th. Separately, honor the documented exponential backoff by replacing the flat asyncio.sleep(0.5) with a growing delay plus jitter.

Details

Severity 🔴 critical
Path nemo_gym/server_utils.py:224
Finding ID ERR-8508619d
Found by error-quality-auditor
Workstream [VDR][v0.5.0] Runtime reliability
Status ⟳ also reported 2026-06-30 (as ERR-967ecc03) — still unfixed

Evidence

$ python -c 'await request("GET","http://127.0.0.1:1/health")' with 8s wait_for -> STILL RETRYING after 8.0s -> UNBOUNDED (server_utils.py:194 MAX_NUM_TRIES=3; :198 PRINT_INTERVAL=100)

DX review Gym-1-20260730170035 · target ref e446e4f4 · 2026-07-30 · tracker #2214

Activity

  1. added
    vdr
    on Jul 30, 2026
  2. anwithk commented on Jul 30, 2026

    @anwithk
    ContributorAuthor

    Verified error profile

    A question came up on which branch actually catches an unreachable server — the intuition being that a connection failure would fall through to the generic except Exception at server_utils.py#L248 and therefore be printed and bounded.

    It does not. A connection error never reaches L248.

    ClientConnectorError (connection refused) and ClientConnectorDNSError (DNS failure) are both subclasses of ClientOSError:

    ClientConnectorError → ClientOSError → ClientConnectionError → ClientError → OSError
    

    Python evaluates except clauses top-down, so except ClientOSError at L236 catches them before L248 is ever considered. Confirmed on the aiohttp version we pin (3.14.3).

    Which branch catches what

    Failure mode Exception Caught at Bounded? First output
    Connection refused (internal or external) ClientConnectorError L236 ClientOSError ❌ never raises ~50s
    DNS failure (external host) ClientConnectorDNSError L236 ClientOSError ❌ never raises ~50s
    Peer drops mid-request ServerDisconnectedError L224 ❌ never raises ~50s
    Timeout ServerTimeoutError / asyncio.TimeoutError L248 Exception ✅ 3 tries immediate
    HTTP / other error ClientResponseError, plain OSError L248 Exception ✅ 3 tries immediate

    Only the last two rows respect MAX_NUM_TRIES.

    _internal does not change this

    _internal only gates the print at L253 — and that is inside the bounded branch (which raises at L259). Neither connection-error branch inspects _internal at all, so an external server hangs exactly the same as a Gym-spawned internal one.

    Runtime repro

    Against a closed port, through the real request():

    import asyncio, time, io, contextlib
    from nemo_gym.server_utils import request
    
    async def probe(url, internal, budget):
        buf, t0 = io.StringIO(), time.monotonic()
        try:
            with contextlib.redirect_stdout(buf):
                await asyncio.wait_for(request("GET", url, _internal=internal), timeout=budget)
            return "returned", time.monotonic() - t0, buf.getvalue()
        except asyncio.TimeoutError:
            return "STILL RETRYING (never raised)", time.monotonic() - t0, buf.getvalue()
        except Exception as e:
            return f"raised {type(e).__name__}", time.monotonic() - t0, buf.getvalue()
    
    async def main():
        for internal in (False, True):
            outcome, el, out = await probe("http://127.0.0.1:1/x", internal, 60)
            first = next((l for l in out.splitlines() if l.strip()), "(NOTHING PRINTED)")
            print(f"_internal={internal} -> {outcome} after {el:.0f}s\n    {first[:140]}")
    
    asyncio.run(main())
    MAX_NUM_TRIES = 3 | PRINT_INTERVAL = 100
    _internal=False -> STILL RETRYING (never raised) after 60s
        [request_retry url=http://127.0.0.1:1/x error=ClientOSError retry=100 elapsed_s=49.7] Hit 100 global `ClientOSError` ...
    _internal=True  -> STILL RETRYING (never raised) after 60s
        [request_retry url=http://127.0.0.1:1/x error=ClientOSError retry=80 elapsed_s=39.7] Hit 200 global `ClientOSError` ...
    

    Second issue this surfaced: the print counter is global, not per-request

    _NUM_CLIENT_OS_ERROR is a module-level global. Note the second probe above printed at retry=80, not retry=100, because the counter had already reached 200 during the first probe. Consequences:

    • The print cadence depends on unrelated concurrent traffic rather than on this request's own retry count.
    • The retry=N field in the message does not correspond to the retry count of the URL being named.
    • Under high concurrency the message fires often but names an arbitrary one of the failing URLs; with a single failing request it takes a full ~50s.

    Implication for the fix

    Capping needs to happen in the two connection branches specifically — moving the cap into the generic handler will not help, since connection errors never get there. Suggested:

    1. Apply MAX_NUM_TRIES to the ServerDisconnectedError and ClientOSError branches, re-raising the original exception once exhausted with the URL and likely cause (server not started / wrong port).
    2. Print on the first failure, not every 100th.
    3. Make the retry counter per-request rather than a module global (or keep the global purely for aggregate telemetry and drive the message off the local retries).
    4. Replace the flat asyncio.sleep(0.5) with growing delay + jitter, which is what the docs already claim happens.

    Verified against ba167e07; nemo_gym/server_utils.py is byte-identical to e446e4f4, the ref the original review ran on, so nothing has drifted.

  3. 10 remaining items

  4. moved this from Dev WIP to Review Todo in NeMo Gym 0.6.0 - Sept 2on Aug 27, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

Rolloutvdr

Type

No type

Projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions