tests: write the fake child's argv log with one mv, not append-per-line
Some checks failed
android-ci / android (pull_request) Successful in 12m25s
ci / test (pull_request) Failing after 4m11s
ci / sdk (pull_request) Successful in 1m20s
ci / fuzz (pull_request) Successful in 5m28s

The wallet-child tests learn a spawned stand-in's port by polling its argv
log, and `fake_bin`/`fake_child_bin` truncated the log and then appended
one line per argument -- so a poller could read a prefix. A truncated port
is a *valid* u16 ("427" out of "42765"), so `wait_for_child_rpc_port`
happily returned a port nothing was listening on and the restart's
`open_wallet` died with `Connection refused` after its 10s budget; the
same prefix read is what `loopback_and_clearnet_remotes_carry_no_proxy...`
printed with its `--daemon-address` value missing.

Both tests failed on the first CI run of this branch (ci / test) and are
green in isolation, which is the signature of this race rather than of a
code defect. The argv now lands in the log with a single `mv`, so a reader
sees either no log or the complete one.

Measured with a tight read loop (argv-race-probe.sh): the append version
was caught mid-write 1/300 reads, the mv version 0/300.
This commit is contained in:
agent 2026-09-22 14:33:32 -04:00
commit 8d80a4fd55
No known key found for this signature in database
2 changed files with 16 additions and 5 deletions

View file

@ -1233,17 +1233,24 @@ mod tests {
}
/// A stand-in for monerod / monero-wallet-rpc: records its argv, then parks.
///
/// The argv lands in `<log>` with one `mv`, not a truncate-then-append: a
/// reader must never see half an argv. It did — the poll below could catch
/// `--rpc-bind-port` while the port was still being written and parse
/// `427` out of `42765`, a valid-but-wrong port, and the test then bound a
/// mock nobody dialled.
fn fake_bin(dir: &Path, name: &str, log: &Path) -> PathBuf {
let path = dir.join(name);
let mut f = fs::File::create(&path).unwrap();
writeln!(f, "#!/bin/sh").unwrap();
writeln!(f, ": > '{}'", log.display()).unwrap();
writeln!(f, "tmp='{}'.$$", log.display()).unwrap();
writeln!(f, ": > \"$tmp\"").unwrap();
writeln!(
f,
"for a in \"$@\"; do printf '%s\\n' \"$a\" >> '{}'; done",
log.display()
"for a in \"$@\"; do printf '%s\\n' \"$a\" >> \"$tmp\"; done"
)
.unwrap();
writeln!(f, "mv -f \"$tmp\" '{}'", log.display()).unwrap();
writeln!(f, "sleep 30").unwrap();
drop(f);
let mut perms = fs::metadata(&path).unwrap().permissions();