is_fork_alive

Documentation for eth_defi.testing.anvil_fork_pool.is_fork_alive function.

is_fork_alive(launch, timeout=5.0)

Check that a pooled Anvil fork still answers JSON-RPC promptly.

Used by AnvilForkPool.get_launch() to decide whether a reused fork is still healthy or must be recycled. See the “Wedged-fork recycling” section of this module’s docstring for the full rationale and the measurements that motivated it.

Three deliberate design choices, each of which matters:

  1. ``eth_chainId`` as the probe call. Anvil answers it from memory without touching the upstream archive, so a slow reply isolates Anvil process unresponsiveness from upstream provider slowness. Probing with a state-reading call (eth_getBalance, eth_call) would conflate the two and could wrongly recycle a healthy fork that is merely waiting on a cold archive read.

  2. Raw ``requests`` instead of Web3. Going through create_multi_provider_web3() would inherit POOL_WEB3_HTTP_TIMEOUT (60 s read) — the very timeout this probe exists to avoid paying once per test in the group. A raw POST lets us bound the check at POOL_LIVENESS_TIMEOUT.

  3. Fail closed. Any failure — timeout, refused connection, HTTP error, or an unparseable body — is treated as “not usable”. Relaunching a fork that was actually fine costs one extra fork (seconds, and the RPC cache is warm); not relaunching a wedged one costs every remaining test in the group a 60 s timeout.

Parameters
Returns

True when Anvil replied with a well-formed JSON-RPC result within the timeout, False otherwise (caller should dispose and relaunch).

Return type

bool