Something I keep hitting: the client asks the server for something (lib.callback.await, a QBCore callback, your own event pair), the server errors halfway or the player drops, and the client just sits there. NUI stuck on a spinner, controls still locked, no message at all.
What I do now:
Every path on the server side returns something, including the failure paths (return false, ‘reason’ instead of falling off the end of the function).
The client frees its UI state and controls after the call whether it worked or not, not only in the happy path.
A nil result counts as failed: show a notify and close the menu instead of leaving it open.
A per-player busy flag, so mashing the button doesn’t queue five identical calls.
Curious how others handle it. Do you put a timeout on the client side, or rely on whatever the callback library does? And has anyone seen a callback never return after the player disconnected mid-call?
I put a timeout on the client side as well, because even with every server path returning something, a player dropping mid-call or a resource restarting leaves the callback with nothing to return. I usually wrap the await with a 5-10 second limit, then treat a timeout exactly like a failure: notify the player, close the menu and release the controls. The per-player busy flag is a good call too — without it, mashing the button while the first call is hanging just queues another call that hangs the same way.
Depends a lot on which callback lib you’re on, because they behave very differently when things go wrong:
ox_lib (and so Qbox, since qbx_core uses it)
The server handler runs inside pcall. If it errors, the error prints in the server console and the client gets nil back. That’s why “nil = failed” is the right rule.
There is a built-in timeout, but it’s ox:callbackTimeout, default 300000 ms (5 min). Nobody waits that long on a spinner. It’s read with GetConvarInt on both sides, so for the client you need a replicated convar:
setr ox:callbackTimeout 15000
Each resource reads it when ox_lib loads, so put it near the top of server.cfg, before your ensure lines.
When it times out, the promise is rejected, so lib.callback.await throws inside your thread. It doesn’t return nil. If you clean up after the call, wrap it:
local ok, result = pcall(lib.callback.await, 'myres:buy', false, itemId)
SetNuiFocus(false, false)
if not ok or not result then
return lib.notify({ type = 'error', description = 'Something went wrong' })
end
Also, if you pass a delay (2nd arg) and the call is still throttled, it returns nil without ever reaching the server. One more reason to treat nil as failed.
QBCore (QBCore.Functions.TriggerCallback)
No timeout and no pcall. If the server handler errors, or just returns without calling cb, the client waits forever.
Pending callbacks are stored by name. Fire the same callback twice before the first one answers, and the second overwrites the first, so the first await never resolves. Your per-player busy flag fixes more than just spam here.
If you need a timeout, race it yourself:
local p = promise.new()
QBCore.Functions.TriggerCallback('myres:getData', function(res) p:resolve(res) end)
SetTimeout(10000, function() if p.state == 0 then p:resolve(nil) end end)
local result = Citizen.Await(p)
Disconnects: if the client drops mid-call, its whole script state is gone, so there’s nothing left waiting. The case that actually hangs is the other direction: the server doing lib.callback.await('name', playerId) to a player who leaves. ox_lib only checks DoesPlayerExist when it sends the request. After that, the server thread waits until the timeout above and then throws. So if you call clients from the server, keep an eye on playerDropped, and don’t hold locks or “busy” state across that await.