[deprecated] Race condition error upon await ctx.auth.getUserIdentity();
I recently encountered a race condition issue when implementing the getById query in my application. The initial code I had written is as follows:
4 Replies
This code resulted in a race condition error, as shown in the attached screenshot. To mitigate the issue, I made the following changes:
The race condition I encountered was likely due to the way the ctx.db.get(args.id) call was being made. By first fetching the space data and then checking for the user and membership, I was able to avoid the race condition.
However, I believe there may be a more optimal solution to this problem. Could you please provide guidance on the best way to structure this query to avoid race conditions and ensure the most efficient data retrieval?
Ronin is my colleague.
To add on the description of this problem, we need help predicting the order of operations that a Convex function executes.
We have faced this issue for months. This is our most common source of production issues.
We are not aware of a predictable pattern of which users will face the issue. We do observe that
1) the users who sees this application error from the race condition always face this race condition problem. In other words, the user can keep refreshing all day and keep seeing the error.
2) And a user who does not face the race condition, will not be able to reproduce the race condition.
Could you show the Convex logs fro the dashboard this instead of the client-side error? It's hard to tell what the error is without a stack trace.
@Ronin you can type
npx convex dashboard
in this directory to get to the dashboard, then watch the logs as you trigger this issue.
The error says "getInfoById," not getById like the code you've shown. Could you show the code for getInfoById
?
Are you using this code inside another function and running it async?@ballingt here is the link of the new support post with better explaination of the problem with more context
https://discord.com/channels/1019350475847499849/1316445807066746942