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:
``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.Raw ``requests`` instead of Web3. Going through
create_multi_provider_web3()would inheritPOOL_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 atPOOL_LIVENESS_TIMEOUT.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
launch (eth_defi.provider.anvil.AnvilLaunch) – Pooled Anvil launch to probe. Only its
json_rpc_urlis used, so this is cheap to call and safe on a process that may already be dead.timeout (float) – Seconds to wait for the reply before declaring the fork wedged. Defaults to
POOL_LIVENESS_TIMEOUT.
- Returns
Truewhen Anvil replied with a well-formed JSON-RPC result within the timeout,Falseotherwise (caller should dispose and relaunch).- Return type