Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug] Blocks on anvil node hang after some time #1078

Closed
StackOverflowExcept1on opened this issue Jul 19, 2024 · 3 comments · Fixed by #1081
Closed

[Bug] Blocks on anvil node hang after some time #1078

StackOverflowExcept1on opened this issue Jul 19, 2024 · 3 comments · Fixed by #1081
Labels
bug Something isn't working

Comments

@StackOverflowExcept1on
Copy link
Contributor

StackOverflowExcept1on commented Jul 19, 2024

Component

node-bindings, provider, pubsub

What version of Alloy are you on?

alloy v0.1.4
anvil v0.2.0 (e903484 2024-07-19T00:35:00.564315108Z)

Operating System

Linux

Describe the bug

Minimal example:

git clone git@github.com:StackOverflowExcept1on/alloy-anvil-bug.git
cd alloy-anvil-bug
cargo run --release
2024-07-19 13:01:50.523 DEBUG tungstenite::handshake::client: Client handshake done.
2024-07-19 13:01:50.523 DEBUG alloy_rpc_client::call: sending request method=eth_subscribe id=0
2024-07-19 13:01:51.523  INFO alloy_anvil_bug: block_number = 1
2024-07-19 13:01:52.523  INFO alloy_anvil_bug: block_number = 2
2024-07-19 13:01:53.522  INFO alloy_anvil_bug: block_number = 3
2024-07-19 13:01:54.522  INFO alloy_anvil_bug: block_number = 4
...
2024-07-19 13:03:37.522  INFO alloy_anvil_bug: block_number = 107
^^^ in my case the hang occurs on this block
@StackOverflowExcept1on StackOverflowExcept1on added the bug Something isn't working label Jul 19, 2024
@StackOverflowExcept1on
Copy link
Contributor Author

When I start reading stdout through BufReader everything works as intended.

let mut anvil = Anvil::new().block_time(1).try_spawn()?;
let provider = ProviderBuilder::new()
    .on_builtin(&anvil.ws_endpoint())
    .await?;

//workaroud:
let child = anvil.child_mut();
let stdout = child.stdout.take().unwrap();

tokio::task::spawn(async {
    let mut reader = BufReader::new(stdout);
    loop {
        let mut line = String::new();
        reader.read_line(&mut line).unwrap();
    }
});

let block_subscription = provider.subscribe_blocks().await?;
let mut block_stream = block_subscription.into_stream();

while let Some(block) = block_stream.next().await {
    let block_number = block.header.number.expect("failed to get block number");
    tracing::info!("block_number = {block_number}");
}

@StackOverflowExcept1on
Copy link
Contributor Author

To speed up reproduction use .block_time_f64(0.001):

let anvil = Anvil::new().block_time_f64(0.001).try_spawn()?;

@StackOverflowExcept1on
Copy link
Contributor Author

StackOverflowExcept1on commented Jul 19, 2024

Very similar problem, but in foundry foundry-rs/foundry#3414

https://doc.rust-lang.org/std/process/struct.Stdio.html#method.piped

Writing more than a pipe buffer’s worth of input to stdin without also reading stdout and stderr at the same time may cause a deadlock. This is an issue when running any program that doesn’t guarantee that it reads its entire stdin before writing more than a pipe buffer’s worth of output. The size of a pipe buffer varies on different targets.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant