File tree 3 files changed +32
-4
lines changed
3 files changed +32
-4
lines changed Original file line number Diff line number Diff line change @@ -37,6 +37,7 @@ thiserror.workspace = true
37
37
tracing.workspace = true
38
38
url.workspace = true
39
39
40
+
40
41
[dev-dependencies ]
41
42
ci_info.workspace = true
42
43
tokio = { workspace = true , features = [" macros" , " rt-multi-thread" ] }
Original file line number Diff line number Diff line change @@ -202,6 +202,7 @@ pub struct Geth {
202
202
data_dir : Option < PathBuf > ,
203
203
chain_id : Option < u64 > ,
204
204
insecure_unlock : bool ,
205
+ keep_err : bool ,
205
206
genesis : Option < Genesis > ,
206
207
mode : NodeMode ,
207
208
clique_private_key : Option < SigningKey > ,
@@ -369,6 +370,14 @@ impl Geth {
369
370
self
370
371
}
371
372
373
+ /// Keep the handle to geth's stderr in order to read from it.
374
+ ///
375
+ /// Caution: if the stderr handle isn't used, this can end up blocking.
376
+ pub const fn keep_stderr ( mut self ) -> Self {
377
+ self . keep_err = true ;
378
+ self
379
+ }
380
+
372
381
/// Adds an argument to pass to `geth`.
373
382
///
374
383
/// Pass any arg that is not supported by the builder.
@@ -635,7 +644,20 @@ impl Geth {
635
644
}
636
645
}
637
646
638
- child. stderr = Some ( reader. into_inner ( ) ) ;
647
+ if self . keep_err {
648
+ // re-attach the stderr handle if requested
649
+ child. stderr = Some ( reader. into_inner ( ) ) ;
650
+ } else {
651
+ // We need to consume the stderr otherwise geth is non-responsive and RPC server results
652
+ // in connection refused.
653
+ // See: <https://github.com/alloy-rs/alloy/issues/2091#issuecomment-2676134147>
654
+ std:: thread:: spawn ( move || {
655
+ let mut buf = String :: new ( ) ;
656
+ loop {
657
+ let _ = reader. read_line ( & mut buf) ;
658
+ }
659
+ } ) ;
660
+ }
639
661
640
662
Ok ( GethInstance {
641
663
pid : child,
Original file line number Diff line number Diff line change @@ -107,9 +107,14 @@ mod test {
107
107
async_ci_only ( || async move {
108
108
run_with_tempdir ( "geth-test-1" , |temp_dir_1| async move {
109
109
run_with_tempdir ( "geth-test-2" , |temp_dir_2| async move {
110
- let geth1 = Geth :: new ( ) . disable_discovery ( ) . data_dir ( & temp_dir_1) . spawn ( ) ;
111
- let mut geth2 =
112
- Geth :: new ( ) . disable_discovery ( ) . port ( 0u16 ) . data_dir ( & temp_dir_2) . spawn ( ) ;
110
+ let geth1 =
111
+ Geth :: new ( ) . disable_discovery ( ) . keep_stderr ( ) . data_dir ( & temp_dir_1) . spawn ( ) ;
112
+ let mut geth2 = Geth :: new ( )
113
+ . disable_discovery ( )
114
+ . keep_stderr ( )
115
+ . port ( 0u16 )
116
+ . data_dir ( & temp_dir_2)
117
+ . spawn ( ) ;
113
118
114
119
let provider1 = ProviderBuilder :: new ( ) . on_http ( geth1. endpoint_url ( ) ) ;
115
120
let provider2 = ProviderBuilder :: new ( ) . on_http ( geth2. endpoint_url ( ) ) ;
You can’t perform that action at this time.
0 commit comments