You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
It may rarely happen the port we asked with get_available_port is in the
meantime used by another process, with this commit we retry to spawn the process
with different ports
/// Bitcoind command line arguments containing no spaces like `vec!["-dbcache=300", "-regtest"]`
133
134
/// note that `port`, `rpcport`, `connect`, `datadir`, `listen`
@@ -150,6 +151,13 @@ pub struct Conf<'a> {
150
151
/// It may be useful for example to set to a ramdisk so that bitcoin nodes spawn very fast
151
152
/// because their datadirs are in RAM
152
153
pubtmpdir:Option<PathBuf>,
154
+
155
+
/// Try to spawn the process `attempt` time
156
+
///
157
+
/// The OS is giving available ports to use, however, they aren't booked, so it could rarely
158
+
/// happen they are used at the time the process is spawn. When retrying other available ports
159
+
/// are returned reducing the probability of conflicts to negligible.
160
+
pubattempts:u8,
153
161
}
154
162
155
163
implDefaultforConf<'_>{
@@ -160,6 +168,7 @@ impl Default for Conf<'_> {
160
168
p2p:P2P::No,
161
169
network:"regtest",
162
170
tmpdir:None,
171
+
attempts:3,
163
172
}
164
173
}
165
174
}
@@ -224,7 +233,7 @@ impl BitcoinD {
224
233
default_args,
225
234
p2p_args
226
235
);
227
-
letmut process = Command::new(exe)
236
+
letmut process = Command::new(exe.as_ref())
228
237
.args(&default_args)
229
238
.args(&p2p_args)
230
239
.args(&conf.args)
@@ -235,8 +244,15 @@ impl BitcoinD {
235
244
// wait bitcoind is ready, use default wallet
236
245
let client = loop{
237
246
ifletSome(status) = process.try_wait()? {
238
-
error!("early exit with: {:?}", status);
239
-
returnErr(Error::EarlyExit(status));
247
+
if conf.attempts > 0{
248
+
warn!("early exit with: {:?}. Trying to launch again ({} attempts remaining), maybe some other process used our available port", status, conf.attempts);
249
+
letmut conf = conf.clone();
250
+
conf.attempts -= 1;
251
+
returnSelf::with_conf(exe,&conf);
252
+
}else{
253
+
error!("early exit with: {:?}", status);
254
+
returnErr(Error::EarlyExit(status));
255
+
}
240
256
}
241
257
thread::sleep(Duration::from_millis(500));
242
258
assert!(process.stderr.is_none());
@@ -380,7 +396,6 @@ mod test {
380
396
#[test]
381
397
fntest_bitcoind(){
382
398
let exe = init();
383
-
println!("{}", exe);
384
399
let bitcoind = BitcoinD::new(exe).unwrap();
385
400
let info = bitcoind.client.get_blockchain_info().unwrap();
386
401
assert_eq!(0, info.blocks);
@@ -425,6 +440,7 @@ mod test {
425
440
426
441
#[test]
427
442
fntest_multi_p2p(){
443
+
let _ = env_logger::try_init();
428
444
letmut conf_node1 = Conf::default();
429
445
conf_node1.p2p = P2P::Yes;
430
446
let node1 = BitcoinD::with_conf(exe_path().unwrap(),&conf_node1).unwrap();
0 commit comments