heroiclabs / nakama

Distributed server for social and realtime games and apps.
https://heroiclabs.com
Apache License 2.0
9.01k stars 1.1k forks source link

Critical DB operations are being cancelled in our hooks when client disconnects #842

Closed brianwinterpixel closed 2 years ago

brianwinterpixel commented 2 years ago

Description

We found a number of new accounts that are not being given critical initial metadata/wallet/storage data in authentication after hooks.

After searching for a while, we discovered the issue is being caused by the error timeout: context canceled in a storage request to read the default account configuration from a record.

Searching the issue, we found several forum posts (here and here) explaining why this is happening. To my understanding, the context is cancelled on client disconnect to reduce load, presuming the client won't be there to receive a response. The only problem is that we don't want nor expect this optimization. We now have dozens of accounts that are unable to use core features of our application due to metadata/wallet/storage records that were never initialized.

We're looking for a simple way to circumvent or disable this behavior in our Lua backend. If we can save resources by allowing storage operations to cancel on client disconnect, that should be an opt-in parameter.

Steps to Reproduce

  1. Add an after hook to AuthenticateEmail that performs storage operations
  2. (??) we're not sure, perhaps people have bad connections or are closing the game in the middle of an auth request
  3. Logs show timeout: context canceled for important storage operations

Expected Result

Code should only error if Nakama loses DB connection or a DB operation takes way too long.

Actual Result

Code can error anywhere we make DB requests.

Context

Godot client, Lua backend

Your Environment

Nakama 3.10 (forked from 1d0527e0) Postgres Docker

mofirouz commented 2 years ago

This is not a bug nor an unintended behaviour of the system. You've correctly posted this on the forum and one the community members will reply soon.