Skip to content

A suspended device stops sending pings, so peers drop it with “read timeout” #10940

Open

Description

@Elliotisnt

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

  1. added
    bug
    on Oct 26, 2026
  2. added theissue type on Oct 26, 2026
  3. added
    needs-triage
    on Oct 26, 2026
  4. calmh commented on Oct 26, 2026

    @calmh
    Member

    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?

     lib/protocol/protocol.go | 4 ++--
     1 file changed, 2 insertions(+), 2 deletions(-)
    
    diff --git i/lib/protocol/protocol.go w/lib/protocol/protocol.go
    index ef416cd09..9fd3e8e86 100644
    --- i/lib/protocol/protocol.go
    +++ w/lib/protocol/protocol.go
    @@ -1031,7 +1031,7 @@ func (c *rawConnection) internalClose(err error) {
     // results in an effecting ping interval of somewhere between
     // PingSendInterval/2 and PingSendInterval.
     func (c *rawConnection) pingSender() {
    -	ticker := time.NewTicker(PingSendInterval / 2)
    +	ticker := time.NewTicker(time.Second)
     	defer ticker.Stop()
     
     	for {
    @@ -1056,7 +1056,7 @@ func (c *rawConnection) pingSender() {
     // but we expect pings in the absence of other messages) within the last
     // ReceiveTimeout. If not, we close the connection with an ErrTimeout.
     func (c *rawConnection) pingReceiver() {
    -	ticker := time.NewTicker(ReceiveTimeout / 2)
    +	ticker := time.NewTicker(time.Second)
     	defer ticker.Stop()
     
     	for {
  5. Elliotisnt commented on Oct 27, 2026

    @Elliotisnt
    Author

    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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugneeds-triage

    Type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions