foundry-rs / foundry

Foundry is a blazing fast, portable and modular toolkit for Ethereum application development written in Rust.
https://getfoundry.sh
Apache License 2.0
8.34k stars 1.77k forks source link

Anvil IPC response does not contain a newline, breaks web3py v7 AsyncIPCProvider #9203

Open BowTiedDevil opened 1 month ago

BowTiedDevil commented 1 month ago

Component

Anvil

Have you ensured that all of these are up to date?

What version of Foundry are you on?

forge 0.2.0 (192a5a2 2024-10-26T00:22:40.192959901Z)

What command(s) is the bug in?

anvil

Operating System

Linux

Describe the bug

Web3py v7 added an async IPC provider. I have been testing it and discovered that it hangs when communicating with Anvil's IPC implementation. It works as expected with Reth's IPC implementation.

Comparing the responses from the IPC, I can see that Anvil omits the newline at the end of the response. Reth includes the newline.

Here are two responses captured from my node and an Anvil fork:

bytearray(b'{"jsonrpc":"2.0","id":0,"result":"reth/v1.1.0-1ba631ba/x86_64-unknown-linux-gnu"}\n')
bytearray(b'{"jsonrpc":"2.0","id":0,"result":"anvil/v0.2.0"}')

The hang occurs because the async IPC provider defers reading from the socket to asyncio's StreamReader.readline() method, which expects a \n separator. Not finding it, it continues to read from the socket until the timeout is reached.

I don't know if a newline is a convention or a requirement — it's unclear if web3py's newline expectation is wrong, or whether the omission is something Anvil should correct.