Skip to content

Commit 7a8efef

Browse files
author
Mema
committed
fix: handle tailscale file cp hang in send script
tailscale file cp can hang indefinitely waiting for the peer to accept. Use background-process + 2s probe pattern to detect successful initiation and detach, rather than blocking forever.
1 parent 72ea9fb commit 7a8efef

1 file changed

Lines changed: 21 additions & 4 deletions

File tree

tailscale-send.sh

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -61,16 +61,33 @@ pick_device() {
6161

6262
send_files() {
6363
local device=$1; shift
64-
local ok=0 fail=0 f
64+
local ok=0 fail=0 f pid
6565

6666
for f in "$@"; do
6767
[[ -e "$f" ]] || { echo "skipping (not found): $f" >&2; ((fail++)); continue; }
6868
echo "sending: $f -> $device" >&2
69-
if tailscale file cp "$f" "$device:" 2>/dev/null; then
69+
70+
# tailscale file cp can hang waiting for the peer;
71+
# background it and check after 2s whether it's still running
72+
tailscale file cp "$f" "$device:" 2>/dev/null &
73+
pid=$!
74+
sleep 2
75+
76+
if kill -0 "$pid" 2>/dev/null; then
77+
# still running — transfer initiated, detach
78+
disown "$pid" 2>/dev/null || true
79+
echo "transfer started: $f" >&2
7080
((ok++))
7181
else
72-
echo "FAILED: $f" >&2
73-
((fail++))
82+
wait "$pid" 2>/dev/null || true
83+
local rc=$?
84+
if [ "$rc" -eq 0 ]; then
85+
echo "transfer complete: $f" >&2
86+
((ok++))
87+
else
88+
echo "FAILED: $f (exit $rc)" >&2
89+
((fail++))
90+
fi
7491
fi
7592
done
7693

0 commit comments

Comments
 (0)