Error : "Context canceled" and "Context deadline exceed"

Hello everybody, I’ve many errors about “Context canceled” and “Context deadline exceed” in important parts of RPC codes, Like executing SQL, updating wallets and … Which causes scripts to be run incompletely, and making the bad experience for end-users.
How can I prevent these errors in server/app side? What’s the difference between “Context canceled” and “Context deadline exceed”? and How can I force my script to be run even when context is canceled?

Context cancelled is caused when the original request was cancelled. Most frequently, it refers to the client connection going away and therefore Nakama cancels in-flight requests (to various subsystems, including the database) to avoid performing unnecessary work.

“Context deadline exceeded” means that the request took longer to finish than allowed and the system killed the request. This could refer to the client connections, or database connections or any other subsystem.

Most of the time, this could happen when interacting with a query that is performing poorly on the database. In this case, I’d suggest checking your query and your database settings to ensure optimum performance.

1 Like

Thanks,
In my scenario, I have an RPC that does many works (writing score in many leaderboards, sending notifications, giving the user some rewards (Updating wallet))
What’s the best practice to handle this scenario with the nakama, within avoiding errors like “Context deadline exceed”?
Should I pass works like “Sending notifications” to a message broker server (Ex: RabbitMQ) to be run with delay?

You can pass the work (or some part of it) to a background goroutine if you’re using the Go runtime. With Lua your best bet is to hand off the work to another service via a HTTP request.

It’s not very common to need to do this but it seems you’re trying to do a lot of work in one RPC function and the client is timing out waiting for a response.