diff --git a/.github/scripts/smoke-test.sh b/.github/scripts/smoke-test.sh index 49846d8..0cb2d88 100755 --- a/.github/scripts/smoke-test.sh +++ b/.github/scripts/smoke-test.sh @@ -2,7 +2,8 @@ # Run-time smoke test for a built rapidmasque binary on the target OS (used # in the OpenBSD VMs to check the cross-built binaries). Brings up a server # and a client on loopback and tunnels UDP to an echo target, plain, with ECH, -# and (on OpenBSD) with an extra multipath path in its own routing table. +# and (on OpenBSD) with an extra multipath path, with and without its own +# routing table. # Usage: smoke-test.sh BINARY TOOLS_DIR # TOOLS_DIR holds udpecho/udpsend/gencert from testing/ built for the target. set -eu @@ -30,37 +31,68 @@ test -n "$ech" pids="$pids $!" "$bin" serve --addr 0.0.0.0:4433 --rules "$work/rules.json" \ --cert "$work/cert.pem" --key "$work/key.pem" --ech-key "$work/ech.pem" \ + --stats-listen 127.0.0.1:9100 \ > "$work/server.log" 2>&1 & -pids="$pids $!" +server_pid=$! +pids="$pids $server_pid" sleep 2 +# fail MESSAGE CLIENT_PID CLIENT_STATS_PORT CLIENT_LOG: report a failed check +# with what both sides were doing, and exit. +fail() { + echo "FAIL: $1" + if [ "$(uname -s)" = OpenBSD ]; then + echo "--- processes"; ps -o pid,pcpu,state,wchan,command -p "$2,$server_pid" || true + echo "--- client stats"; ftp -V -o - "http://127.0.0.1:$3/stats" 2>&1 || true + echo "--- server stats"; ftp -V -o - "http://127.0.0.1:9100/stats" 2>&1 || true + # Two seconds of both sides' syscalls: a stalled sender shows no + # sendmsg at all. + ktrace -f "$work/client.ktrace" -t c -p "$2" || true + ktrace -f "$work/server.ktrace" -t c -p "$server_pid" || true + sleep 2 + ktrace -C || true + for side in client server; do + echo "--- $side syscalls (2 s)" + kdump -f "$work/$side.ktrace" > "$work/$side.kdump" 2>/dev/null || true + awk '$3 == "CALL" { sub(/\(.*/, "", $4); print $4 }' "$work/$side.kdump" | + sort | uniq -c | sort -rn + grep -E 'RET +[a-z_]+ -1' "$work/$side.kdump" | sort | uniq -c | sort -rn | head -n 20 + done + echo "--- udp sockets"; netstat -an -f inet -p udp || true + fi + kill "$2" 2>/dev/null || true + echo "--- server log"; cat "$work/server.log" + echo "--- client log"; cat "$4" + exit 1 +} + +# path_rx STATS_PORT REMOTE: datagrams received on the client's path to REMOTE. +path_rx() { + ftp -V -o - "http://127.0.0.1:$1/stats" 2>/dev/null | awk -v r="\"remote\": \"$2\"" ' + index($0, r) { f = 1 } + f && /"udp_rx"/ { g = 1 } + g && /"datagrams"/ { gsub(/[^0-9]/, ""); print; exit }' +} + # check NAME PORT [CLIENT_ARGS...]: tunnel one datagram through a fresh client. check() { name="$1" port="$2" shift 2 + stats=$((port + 1000)) "$bin" client --listen "127.0.0.1:$port" \ --endpoint https://localhost:4433/connect --proxy-addr 127.0.0.1:4433 \ + --stats-listen "127.0.0.1:$stats" \ --insecure "$@" > "$work/client-$name.log" 2>&1 & cpid=$! pids="$pids $cpid" - ok="" i=0 - while [ $i -lt 10 ]; do - if "$tools/udpsend" "127.0.0.1:$port" "$name" 2>/dev/null | grep -q "echo:$name"; then - ok=1 - break - fi + until "$tools/udpsend" "127.0.0.1:$port" "$name" 2>/dev/null | grep -q "echo:$name"; do i=$((i + 1)) + [ $i -lt 10 ] || fail "$name" "$cpid" "$stats" "$work/client-$name.log" sleep 1 done kill "$cpid" 2>/dev/null || true - if [ -z "$ok" ]; then - echo "FAIL: $name" - echo "--- server log"; cat "$work/server.log" - echo "--- client log"; cat "$work/client-$name.log" - exit 1 - fi echo "PASS: $name" } @@ -73,39 +105,42 @@ grep -q "ech=true" "$work/server.log" || { } echo "PASS: ECH accepted on the server" -# Per-path routing table (OpenBSD): an extra path towards this host's egress -# address in routing table 0, which unprivileged processes may select. The -# path must come up through its own socket and the tunnel keep working. +# Multipath (OpenBSD): an extra path towards this host's egress address, first +# on the client's main socket, then in routing table 0 (which unprivileged +# processes may select) through a socket of its own. The routing-table path +# must come up and receive replies on that socket. Each client exits right +# after its check, so the server sees connections on several paths close +# while others start: a few rounds of that once caught the server's UDP +# socket stalling for good (fixed in losfair/noq#4: OpenBSD send lock contention). if [ "$(uname -s)" = OpenBSD ]; then egress_ip="$(ifconfig egress 2>/dev/null | awk '/inet /{print $2; exit}')" if [ -z "$egress_ip" ]; then - echo "FAIL: no egress address for the routing-table check" + echo "FAIL: no egress address for the multipath checks" ifconfig exit 1 fi spec="$egress_ip:4433/rtable=0" - "$bin" client --listen 127.0.0.1:6003 \ - --endpoint https://localhost:4433/connect --proxy-addr 127.0.0.1:4433 \ - --insecure --path "$spec" > "$work/client-rtable.log" 2>&1 & - cpid=$! - pids="$pids $cpid" - i=0 - until grep -q "multipath path $spec up" "$work/client-rtable.log"; do - i=$((i + 1)) - if [ $i -gt 10 ]; then - echo "FAIL: path $spec did not come up" - echo "--- server log"; cat "$work/server.log" - echo "--- client log"; cat "$work/client-rtable.log" - exit 1 - fi - sleep 1 + for round in 1 2 3; do + check "multipath-$round" 6005 --path "$egress_ip:4433" + log="$work/client-rtable-$round.log" + "$bin" client --listen 127.0.0.1:6003 \ + --endpoint https://localhost:4433/connect --proxy-addr 127.0.0.1:4433 \ + --stats-listen 127.0.0.1:7003 \ + --insecure --path "$spec" > "$log" 2>&1 & + cpid=$! + pids="$pids $cpid" + i=0 + until grep -q "multipath path $spec up" "$log" && + [ "$(path_rx 7003 "$egress_ip:4433")" -gt 0 ] 2>/dev/null; do + i=$((i + 1)) + [ $i -le 15 ] || fail "path $spec did not come up and receive (round $round)" \ + "$cpid" 7003 "$log" + sleep 1 + done + grep -q "routing table 0: socket" "$log" || + fail "no routing-table socket (round $round)" "$cpid" 7003 "$log" + kill "$cpid" 2>/dev/null || true + echo "PASS: path in routing table 0 up and receiving (round $round)" done - grep -q "routing table 0: socket" "$work/client-rtable.log" || { - echo "FAIL: no routing-table socket" - cat "$work/client-rtable.log" - exit 1 - } - kill "$cpid" 2>/dev/null || true check rtable 6004 --path "$spec" - echo "PASS: path in routing table 0 up" fi diff --git a/AGENTS.md b/AGENTS.md index fa0f262..6e3ab53 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -89,6 +89,12 @@ and documented in `README.md`. (`.github/scripts/smoke-test.sh`) exercises a real `rtable=0` path. OpenBSD has no dual-stack sockets: `quic::client_bind_socket` falls back to the primary's family there. +- OpenBSD UDP send stall (fixed in the losfair/noq fork, losfair/noq#4): a + non-blocking UDP `sendmsg` there fails with EAGAIN when another thread is + sending on the same socket, and noq's tokio sender used to clear write + readiness on it and wait forever for a kqueue write event, silencing every + connection on the socket. It looked like a routing-table bug; the smoke + test's back-to-back multipath rounds reproduce it within a few rounds. - Outgoing datagram queue management (always on, no flags; `quic::DATAGRAM_CODEL`) is noq's `TransportConfig::datagram_send_codel` (CoDel plus a hard `max_delay`, in the losfair/noq fork): the queue that builds up is noq's diff --git a/Cargo.lock b/Cargo.lock index 48901d5..ad643e1 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -563,7 +563,7 @@ dependencies = [ [[package]] name = "noq" version = "1.3.0" -source = "git+https://github.com/losfair/noq?rev=ac785a68744f799056e791e5e1378eab7cfd1f7d#ac785a68744f799056e791e5e1378eab7cfd1f7d" +source = "git+https://github.com/losfair/noq?rev=cad1d3ae29ed1b99f01dfd4498e0bb7d892ef6f6#cad1d3ae29ed1b99f01dfd4498e0bb7d892ef6f6" dependencies = [ "bytes", "cfg_aliases", @@ -583,7 +583,7 @@ dependencies = [ [[package]] name = "noq-proto" version = "1.3.0" -source = "git+https://github.com/losfair/noq?rev=ac785a68744f799056e791e5e1378eab7cfd1f7d#ac785a68744f799056e791e5e1378eab7cfd1f7d" +source = "git+https://github.com/losfair/noq?rev=cad1d3ae29ed1b99f01dfd4498e0bb7d892ef6f6#cad1d3ae29ed1b99f01dfd4498e0bb7d892ef6f6" dependencies = [ "bytes", "derive_more", @@ -609,7 +609,7 @@ dependencies = [ [[package]] name = "noq-udp" version = "1.3.0" -source = "git+https://github.com/losfair/noq?rev=ac785a68744f799056e791e5e1378eab7cfd1f7d#ac785a68744f799056e791e5e1378eab7cfd1f7d" +source = "git+https://github.com/losfair/noq?rev=cad1d3ae29ed1b99f01dfd4498e0bb7d892ef6f6#cad1d3ae29ed1b99f01dfd4498e0bb7d892ef6f6" dependencies = [ "cfg_aliases", "libc", diff --git a/Cargo.toml b/Cargo.toml index b3afae6..880630e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -32,10 +32,10 @@ tokio-stream = "0.1" # Pinned to the losfair/noq fork for per-path scheduling priority, the path # spill threshold and datagram queue management (not in upstream noq). Keep # both crates on the same commit. -noq = { git = "https://github.com/losfair/noq", rev = "ac785a68744f799056e791e5e1378eab7cfd1f7d", default-features = false, features = ["runtime-tokio", "ring", "bloom", "tracing-log"] } +noq = { git = "https://github.com/losfair/noq", rev = "cad1d3ae29ed1b99f01dfd4498e0bb7d892ef6f6", default-features = false, features = ["runtime-tokio", "ring", "bloom", "tracing-log"] } # Direct dep only for `coding::Encodable` (to read a `PathId` for the multipath # AEAD nonce); same commit as noq's own. -noq-proto = { git = "https://github.com/losfair/noq", rev = "ac785a68744f799056e791e5e1378eab7cfd1f7d", default-features = false, features = ["ring", "bloom", "tracing-log"] } +noq-proto = { git = "https://github.com/losfair/noq", rev = "cad1d3ae29ed1b99f01dfd4498e0bb7d892ef6f6", default-features = false, features = ["ring", "bloom", "tracing-log"] } # BoringSSL: the TLS 1.3 handshake (via its QUIC API), ECH, and packet # protection (AEAD + header protection). boring 4 keeps the ECH code identical # to zeromasque's.