RealmSync connection won't stay open (Swift)

I’m following the RChat tutorial to setup a basic chat app.

I can create user accounts and they populate my app user list within Realm and my User collection within Atlas.

Upon logging in though, the user immediately disconnects.

I have a feeling it has something to do with async open being set to false, although the tutorial doesn’t mention that it’s a requirement.

Here’s the output of the xcode console:

2021-04-19 11:48:10.044112-0700 BonkLink[4337:91775] Sync: Connection[1]: Session[1]: client_reset_config = false, Realm exists = false, async open = false, client reset = false

2021-04-19 11:48:10.191365-0700 BonkLink[4337:91775] Sync: Connection[1]: Connected to endpoint ‘3.210.32.164:443’ (from ‘192.168.1.193:52816’)

2021-04-19 11:48:11.352449-0700 BonkLink[4337:91775] Sync: Connection[1]: Disconnected

2021-04-19 11:48:11.353044-0700 BonkLink[4337:91775] Sync: Connection[2]: Session[2]: client_reset_config = false, Realm exists = true, async open = false, client reset = false

User realm location: /Users/guygreenleaf/Library/Developer/CoreSimulator/Devices/E93C2E78-1650-497A-88FC-B469E32EF5E2/data/Containers/Data/Application/50B09FF1-EBAD-4270-ACAE-0065E43BA116/Documents/mongodb-realm/bonklink-cytqk/607dd069e94ba6566559491a/%22user%3D607dd069e94ba6566559491a%22.realm

BusyCounter now out of range.Continuing

2021-04-19 11:48:11.461192-0700 BonkLink[4337:91775] Sync: Connection[2]: Connected to endpoint ‘3.210.32.164:443’ (from ‘192.168.1.193:52818’)

2021-04-19 11:48:12.294444-0700 BonkLink[4337:91775] Sync: Connection[2]: Disconnected

In my logs on Realm when the connection ends, I noticed this:

Logs:
[
“Connection was active for: 0s”,
“Checking if can sync a write for partition = user=607a08427eb1f7538e7478fc”,
“Partition key = user; partition value = 607a08427eb1f7538e7478fc”,
“Checking if partitionKey(607a08427eb1f7538e7478fc) matches user.id(607a08427eb1f7538e7478fc) – false”,
“Checking if can sync a write for partition = user=607a08427eb1f7538e7478fc”,
“Partition key = user; partition value = 607a08427eb1f7538e7478fc”,
“Checking if partitionKey(607a08427eb1f7538e7478fc) matches user.id(607a08427eb1f7538e7478fc) – false”
]

Which leads me to believe something is wrong with my partitioning? I’m not sure at this point.

UPDATE: I’ve now got my logs returning TRUE on checking the partitionkey and user.id, but for some reason i’m getting this:

Session closed after receiving UNBIND event

Which is causing an immediate disconnect.

Any advice on this is greatly appreciated!

@Zip_Chat If you are not getting any error in the server or clients logs then this commonly points to an error in the code where a strong reference is not held to the realm variable. When the code reaches the end of the closure the garbage collector cleans up the references and tears down the sync connection. Be sure to persist the realm reference in a place where the lifecycle is not getting torn down.