makrdev
makrdev4mo ago

Leftover state detected. This typically happens if there are dangling promises...

Uncaught Error: Leftover state detected. This typically happens if there are dangling promises from a previous request. Did you forget to await your promises? Uncaught Error: Cannot invoke syscall during module imports at handler (../../../../convex/collections/storage/documents/actions.ts:154:27) I got this error message when I call an action(node) multiple times. It works if we call it once tho... I don't know how to debug this. Anyone can help? Running actions with useAction and Promise.all(...) When I call sequentially it works.
26 Replies
Convex Bot
Convex Bot4mo ago
Thanks for posting in <#1088161997662724167>. Reminder: If you have a Convex Pro account, use the Convex Dashboard to file support tickets. - Provide context: What are you trying to achieve, what is the end-user interaction, what are you seeing? (full error message, command output, etc.) - Use search.convex.dev to search Docs, Stack, and Discord all at once. - Additionally, you can post your questions in the Convex Community's <#1228095053885476985> channel to receive a response from AI. - Avoid tagging staff unless specifically instructed. Thank you!
makrdev
makrdevOP4mo ago
makrdev
makrdevOP4mo ago
Also, works on cloud.
erquhart
erquhart4mo ago
Would you mind opening this on #self-hosted if it's a self hosted issue nvm, I thought self-hosted was a forum channel, it's just a chat
Barrel Of Lube
Barrel Of Lube3mo ago
+1 similar issue
stefano
stefano2mo ago
+1 similar issue. When I remove the “use node” declaration everything goes fine @Barrel Of Lube @makrdev did you manage to solve this?
makrdev
makrdevOP2mo ago
Nah, we just switched to cloud(dev) because there were too many issues like this on local instance.
stefano
stefano2mo ago
Well I have some clients that run my application on-prem so that is not an option. Could some of the Convex staff look at this? Thanks! Curious, which other problems did you encounter?
makrdev
makrdevOP2mo ago
Works on cloud but not locally kind of problems 🙂 Don’t remember specifically but we ended up using cloud for dev too
nipunn
nipunn2mo ago
It's probably a dangling promise. There's a nice typescript no-floating-promises that can help https://docs.convex.dev/understanding/best-practices/#await-all-promises If it's still happening, you can try to narrow down which line of code is leading to it.
ian
ian2mo ago
To confirm, everyone sees this issue only on self-hosted convex but not on cloud? and not on "use node"?
stefano
stefano2mo ago
I see this issue only on self-hosted AND on the node runtime ("use node") I have carefully checked all the code related to the issue and there's no dangling promise. I have narrowed down the code and found where the issue originates, which is a await ctx.runMutation inside an internalFunction that has been called n times (in my case 5) with a workpool. The internalFunction, as previously said, is inside a "use node" ts file. Unfortunately I can't reproduce the issue in a simple way that I can share...
ian
ian2mo ago
Ah interesting - just FYI calling a function in "use node" from a mutation will not run that function in a node environment. you can't run an action from a mutation, and mutations can't run in node, so the function will run in the v8 default runtime The open-source code has the custom node runtime we use for self-hosted convex (different than the AWS lambda environment where they run in cloud-hosted) Running in local dev mode with non-self-hosted convex should repro it, so if it doesn't that'd be very interesting / maybe a newer backend version fixed it
stefano
stefano2mo ago
Sorry what do you mean by local dev mode?
calling a function in "use node" from a mutation will not run that function in a node environment
you mean also if we schedule the function to run? With ctx.scheduler? In this particular case I am using the component enqueueAction which I think in the background uses a ctx.scheduler
nipunn
nipunn2mo ago
@stefano What do you mean by internalFunction - is it an internalAction, or internalMutation or something else? I am trying to repro - if anyone can provide any kind of code snippet to help with the repro, that would help a lot.
Michal Srb
Michal Srb2mo ago
I don't have a reliable repro, but it's happened to me twice now. 1. Have a "use node" file 2. Have a normal file 3. In "use node" file, have something like:
export const forPerson = action(
async (ctx, { userId }: { userId: PersonID }) => {
// do some query reads and `fetch`es...
await ctx.runMutation(internal.normal.foo, { to: userId });
},
);
export const forPerson = action(
async (ctx, { userId }: { userId: PersonID }) => {
// do some query reads and `fetch`es...
await ctx.runMutation(internal.normal.foo, { to: userId });
},
);
4. In normal file it's just a standard mutation. There are no dangling promises (at least not in my code, definitely not in the mutation, but there could be a dangling fetch if MS graph client is borked, which I doubt). @nipunn
ian
ian2mo ago
npx convex dev where you pick "local" - which runs the open source binary under the hood but you can see the dashboard at dashboard.convex.dev, and it's associated with a project etc.
nipunn
nipunn2mo ago
Oh yeah - I was totally able to repro an issue here. I wasn't able to repro the exact dangling promise issue, but something that I think is relevant. When we moved to node action server to eliminate cold starts (see https://github.com/get-convex/convex-backend/blob/96f59e6ccf6434f2177bf097b8ee4e994f8d7db4/self-hosted/CHANGELOG.md#2025-03-10-5143fec81f146ca67495c12c6b7a15c5802c37e2), we introduced an issue where requests can mess with each other's global state. This appears to be happening. I'm working on a fix. Give me a day or two. Thanks everyone for the reports
stefano
stefano2mo ago
Fantastic, thanks everyone of the team and non for the help, I will give feedback once the fix arrives
Barrel Of Lube
Barrel Of Lube2mo ago
It was an ext library issue 🥀 decided to jus use restapi wth fetch instead of the sdk for that service
nipunn
nipunn2mo ago
I suspect https://github.com/get-convex/convex-backend/commit/24f7d49e327f96299df819890a0ebb8f1a4c90f4 will fix. It'll make it into tomorrow's local dev release (in around 21h) - and I'll double check and release it on Monday. If you want to do early testing - feel free to build from source!
stefano
stefano2mo ago
Thanks for the update but unfortunately I’m out until Monday, I guess I’ll wait the release!
Michal Srb
Michal Srb2mo ago
@nipunn has been released yet? I'm hitting the error more consistently now (I haven't upgraded my local instance - the update should be offered during the start of npx convex dev right?).
nipunn
nipunn2mo ago
not just yet - but going out today. The most recent pre-release on this page has the fix. https://github.com/get-convex/convex-backend/releases We just have to do a tiny bit of sanity testing before we mark it as latest (happening today).
GitHub
Releases · get-convex/convex-backend
The open-source reactive database for app developers - get-convex/convex-backend
nipunn
nipunn2mo ago
@Michal Srb just released for local dev (npx convex dev). Not yet released for self-hosting. Just released for self-hosting too - posting over in the #self-hosted channel shortly
stefano
stefano2mo ago
Can confirm that the fix works! Excellent as always, thank you!

Did you find this page helpful?