Skip to content

fix: drop geth's stderr handle #2104

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

Merged
merged 6 commits into from
Mar 18, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions crates/node-bindings/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ thiserror.workspace = true
tracing.workspace = true
url.workspace = true


[dev-dependencies]
ci_info.workspace = true
tokio = { workspace = true, features = ["macros", "rt-multi-thread"] }
24 changes: 23 additions & 1 deletion crates/node-bindings/src/nodes/geth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,7 @@ pub struct Geth {
data_dir: Option<PathBuf>,
chain_id: Option<u64>,
insecure_unlock: bool,
keep_err: bool,
genesis: Option<Genesis>,
mode: NodeMode,
clique_private_key: Option<SigningKey>,
Expand Down Expand Up @@ -369,6 +370,14 @@ impl Geth {
self
}

/// Keep the handle to geth's stderr in order to read from it.
///
/// Caution: if the stderr handle isn't used, this can end up blocking.
pub const fn keep_stderr(mut self) -> Self {
self.keep_err = true;
self
}

/// Adds an argument to pass to `geth`.
///
/// Pass any arg that is not supported by the builder.
Expand Down Expand Up @@ -635,7 +644,20 @@ impl Geth {
}
}

child.stderr = Some(reader.into_inner());
if self.keep_err {
// re-attach the stderr handle if requested
child.stderr = Some(reader.into_inner());
} else {
// We need to consume the stderr otherwise geth is non-responsive and RPC server results
// in connection refused.
Comment on lines +651 to +652
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we link the issue here

// See: <https://github.com/alloy-rs/alloy/issues/2091#issuecomment-2676134147>
std::thread::spawn(move || {
let mut buf = String::new();
loop {
let _ = reader.read_line(&mut buf);
}
});
}

Ok(GethInstance {
pid: child,
Expand Down
11 changes: 8 additions & 3 deletions crates/provider/src/ext/admin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,9 +107,14 @@ mod test {
async_ci_only(|| async move {
run_with_tempdir("geth-test-1", |temp_dir_1| async move {
run_with_tempdir("geth-test-2", |temp_dir_2| async move {
let geth1 = Geth::new().disable_discovery().data_dir(&temp_dir_1).spawn();
let mut geth2 =
Geth::new().disable_discovery().port(0u16).data_dir(&temp_dir_2).spawn();
let geth1 =
Geth::new().disable_discovery().keep_stderr().data_dir(&temp_dir_1).spawn();
let mut geth2 = Geth::new()
.disable_discovery()
.keep_stderr()
.port(0u16)
.data_dir(&temp_dir_2)
.spawn();

let provider1 = ProviderBuilder::new().on_http(geth1.endpoint_url());
let provider2 = ProviderBuilder::new().on_http(geth2.endpoint_url());
Expand Down
Loading