Realm sync times out after DNS migration: Is DNS caching causing the issue?
0 reputation · 06 Oct 2025, 18:55 UTC
0 reputation · 06 Oct 2025, 18:55 UTC
After moving the Realm Object Server to a new IP address, clients report a persistent connection timeout when attempting to open a synced Realm. The SDK continues to use the previous DNS entry, resulting in a failed WebSocket handshake.
35275 reputation · 07 Oct 2025, 06:49 UTC
Yes, DNS caching is the most likely cause if the SDK is attempting to connect to a stale IP address. Because the Realm SDK relies on the underlying operating system's network stack for name resolution, it does not maintain its own internal DNS cache. If the OS has cached the previous IP address, the WebSocket handshake will fail at the TCP layer, resulting in a connection timeout before the SSL/TLS handshake even begins.
To resolve this, it is critical to distinguish between a network-level timeout and a security-level rejection. These two scenarios present differently in the connection lifecycle:
| Symptom | Likely Cause | Behavior |
|---|---|---|
| Connection Timeout | Stale DNS / Firewall | TCP SYN packets are sent to the old IP and receive no response. |
| Handshake Failure / SSL Error | Certificate Mismatch | TCP connection succeeds, but the TLS handshake fails due to an untrusted or mismatched certificate. |
Since the Realm SDK does not expose a manual "force refresh" method for DNS, you must address the issue at the OS or network level:
sudo dscacheutil -flushcache on macOS).nslookup or dig on the client device to confirm the host resolves to the new IP address.Debug. This will reveal the specific endpoint URL being targeted and help differentiate between a socket timeout and a TLS certificate error.To provide a more specific recommendation, please clarify: Are the timeouts occurring across all client platforms (iOS, Android, Web) or only on a specific OS? DNS caching behavior and TTL adherence vary significantly between mobile operating systems.
Use comments to ask for clarification. Post a solution as an answer.
35,275 reputation · 07 Oct 2025, 06:44 UTC
The Realm SDK uses the OS resolver and will keep a cached address until the underlying socket is closed. A quick way to force a fresh lookup is to close all open Realms and sync sessions, then re‑open them. This causes the SDK to create a new socket, which triggers a new DNS query via the OS.
realm.close() or syncSession.disconnect() for every active Realm.SyncConfiguration.Realm.setLogLevel(.all)) and look for a line like DNS resolved host=sync.realm.io to 203.0.113.42 to confirm the new IP.After this, if the connection still times out, the problem is likely TLS validation; check the session error callbacks for SSLHandshakeFailed or client_reset.