Syncthing 2.1.6 global discovery lookup intermittently times out while the same request succeeds immediately with curl

Hi. This is my first bug report (AI aided to test). When upgrading to 2.1.6 from 1.2.9 I was unable to connect to machines using a relay.

Version

Syncthing v2.1.6

Linux, systemd user service.

Description

Devices configured with dynamic addresses fail to resolve through global discovery on Syncthing 2.1.6.

The same devices connect correctly when an explicit QUIC address is configured manually.

The global discovery lookup URL also works immediately from the same host using curl, both with HTTP/2 and HTTP/1.1.

Network environment

The affected Syncthing host is behind a network detected by Syncthing as:

Symmetric UDP firewall

STUN succeeds and Syncthing correctly detects an external QUIC address.

IPv6 is unavailable on this host, but IPv4 connectivity works correctly.

Reproduction

A remote device is configured using:

addresses = ["dynamic"]

With dynamic, Syncthing does not connect.

The logs show global discovery lookup failures such as:

globalClient.Lookup (
    url=https://discovery-lookup.syncthing.net/v2/?device=<REDACTED_DEVICE_ID>
    error="Get \"https://discovery-lookup.syncthing.net/v2/?device=<REDACTED_DEVICE_ID>\":
    context deadline exceeded
    (Client.Timeout exceeded while awaiting headers)"
)

followed by:

Final lookup results (device=<REDACTED> addresses="[]")
Resolved device <REDACTED> addresses: []

The same timeout behavior is seen for several different remote devices.

Control test: global discovery using curl

From the same host and network:

curl -v --connect-timeout 5 --max-time 15 \
'https://discovery-lookup.syncthing.net/v2/?device=<REDACTED_DEVICE_ID>'

returns immediately:

HTTP/2 200

with valid discovery data containing direct QUIC, TCP and relay addresses.

The same test forcing HTTP/1.1:

curl -v --http1.1 \
  --connect-timeout 5 \
  --max-time 15 \
  'https://discovery-lookup.syncthing.net/v2/?device=<REDACTED_DEVICE_ID>'

also returns immediately:

HTTP/1.1 200 OK

Therefore the issue does not appear to be specific to HTTP/2.

Control test: direct QUIC connection

If the remote device configuration is changed from:

dynamic

to an explicit address:

quic://<REDACTED_PUBLIC_IP>:22000

the connection succeeds correctly:

{
  "address": "<REDACTED_PUBLIC_IP>:22000",
  "connected": true,
  "crypto": "TLS1.3-TLS_AES_128_GCM_SHA256",
  "type": "quic-client",
  "primary": {
    "address": "<REDACTED_PUBLIC_IP>:22000",
    "type": "quic-client"
  }
}

A packet capture also confirms bidirectional UDP traffic between both peers on port 22000.

Therefore the QUIC transport itself works.

Additional logs

Syncthing can establish the TCP connection to the global discovery server:

Dialing direct result tcp discovery-lookup.syncthing.net:443: ... <nil>

but some requests later fail with:

Client.Timeout exceeded while awaiting headers

Announcement connections also show the port-reuse fallback mechanism:

Dialing reuse result tcp discovery-announce-v4.syncthing.net:443:
... connect: cannot assign requested address

Dialing non-reuse result tcp discovery-announce-v4.syncthing.net:443:
... <nil>

IPv6 attempts fail with:

connect: network is unreachable

but IPv4 connectivity works.

Expected behavior

When a remote device is configured as:

addresses = ["dynamic"]

Syncthing should retrieve the addresses returned by global discovery and attempt connections to them.

In this case, the discovery endpoint returns a valid direct QUIC address that is known to work when configured explicitly.

Actual behavior

Global discovery lookups intermittently time out inside Syncthing 2.1.6, resulting in:

addresses=[]

and the device remains disconnected.

The same HTTPS discovery request succeeds immediately using curl from the same host.

Debug logging

The issue was reproduced with tracing enabled for:

STTRACE=discover,dialer,connections,relay/client,stun

I can provide the complete trace if required.

Additional environment information

I can also provide:

syncthing --version
uname -a
systemctl --user show syncthing -p ExecStart -p Environment

if useful.

Everything should be functional at the moment.