Repository navigation
Description
What happened?
My phone (Syncthing v2.1.7) gets dropped by my Windows PC with "read timeout" every 7 to 25 minutes while the phone sleeps: 29 times between 03:00 and 10:50 one night. 19 of those 29 connections lasted 451 to 452 s, the shortest a timeout allows, so the phone sent nothing after the handshake.
pingSender in lib/protocol/protocol.go uses time.NewTicker, which runs on the monotonic clock. That clock stops while the phone is suspended, but the 300 s receive timeout is wall time. Asleep 70 to 95% of the time, 45 s of awake time took 5 to 15 minutes of real time, so the phone's pings stopped. The PC's pings do wake the phone, but the phone doesn't answer them.
Expected: a device that wakes to receive a message also keeps its side of the connection alive.
A local build that pings straight back when any message arrives and the last write is 45 s or older by the wall clock had zero drops from the PC over a 16.7 h night. The phone is already awake for the incoming message, so this costs no extra wake.
To reproduce: connect a phone to an always-on peer, leave it on battery overnight with the screen off and no audio playing (audio keeps the phone awake and hides this), and read the peer's log in the morning.
Syncthing version
v2.1.7 on the phone and the PC
Platform & operating system
Android 17 arm64 (Pixel 10 Pro); the peer is Windows 11 amd64
Browser version
No response
Relevant log output
2026-10-25 04:27:27 INF Established secure connection (device=Z76N436 connection.local=192.168.86.27:22000 connection.remote=<phone-ip>:14035 connection.type=tcp-server connection.lan=false connection.crypto=TLS1.3-TLS_AES_128_GCM_SHA256 connection.prio=30 connection.id=671N1FNOG9TECT9JD66U0IV04Q log.pkg=connections)
2026-10-25 04:34:58 INF Lost device connection (kind=primary device=Z76N436 connection=192.168.86.27:22000-<phone-ip>:14035/tcp-server/TLS1.3-TLS_AES_128_GCM_SHA256/WAN-P30-671N1FNOG9TECT9JD66U0IV04Q error="read timeout" remaining=0 log.pkg=model)
2026-10-25 04:37:20 INF Established secure connection (device=Z76N436 connection.local=192.168.86.27:22000 connection.remote=<phone-ip>:2047 connection.type=tcp-server connection.lan=false connection.crypto=TLS1.3-TLS_AES_128_GCM_SHA256 connection.prio=30 connection.id=671N3KNIFMGHCQ6AI2DODOKKNC log.pkg=connections)
2026-10-25 04:54:51 INF Lost device connection (kind=primary device=Z76N436 connection=192.168.86.27:22000-<phone-ip>:2047/tcp-server/TLS1.3-TLS_AES_128_GCM_SHA256/WAN-P30-671N3KNIFMGHCQ6AI2DODOKKNC error="read timeout" remaining=0 log.pkg=model)
Activity
calmh commentedon Oct 26, 2026
Fascinating, I had no idea Go's timers worked like that, I always thought they'd fire as soon as possible after wakeup if they had expired during sleeping. Does this simple patch help, assuming the phone stays awake for at least a second once woken?
Elliotisnt commentedon Oct 27, 2026
Yes I think this would work! A lot simpler than what I built haha, haven't run your version though.
The phone usually doesn't stay awake for a full second. Shouldn't matter though because the ticker's progress carries from one wake to the next. What I did was when any message came in, and the last write was more than 45 s old from the wall clock, the phone pinged back straight away. It was able to hold the connection to my PC for like 17 hours, compared to the night before it dropped more than 30 times. I think your change will work just as well though.