yarrichar
yarrichar•16mo ago

Error: Connection lost while action was in flight

I've just started to get the following error:
logging.js:39 Uncaught (in promise) Error: [CONVEX A(analytics:summary)] Connection lost while action was in flight
at createError (logging.js:39:1)
at BaseConvexClient.action (client.js:297:24)
logging.js:39 Uncaught (in promise) Error: [CONVEX A(analytics:summary)] Connection lost while action was in flight
at createError (logging.js:39:1)
at BaseConvexClient.action (client.js:297:24)
Not sure what's causing it. Pretty sure I'm doing the right thing. Functions say they're ready / deployed ok. React code:
const fetchSummary = useAction(api.analytics2.analyticsSummary);

useEffect(() => {
fetchSummary({ mvpId: mvpId as Id<"mvp">, minDate: moment().subtract(24, "hours").date() })
.then(result => {
console.log("Analytics result: ", result);
});
}, []);
const fetchSummary = useAction(api.analytics2.analyticsSummary);

useEffect(() => {
fetchSummary({ mvpId: mvpId as Id<"mvp">, minDate: moment().subtract(24, "hours").date() })
.then(result => {
console.log("Analytics result: ", result);
});
}, []);
Convex code:
export const analyticsSummary = action({
args: { mvpId: v.id("mvp"), minDate: v.number() },
handler: async ({ auth, runQuery }, { mvpId, minDate }) => {
return null;
}
});
export const analyticsSummary = action({
args: { mvpId: v.id("mvp"), minDate: v.number() },
handler: async ({ auth, runQuery }, { mvpId, minDate }) => {
return null;
}
});
8 Replies
yarrichar
yarricharOP•16mo ago
Other functions are fine I've tried renaming both the file, and the individual function
ballingt
ballingt•16mo ago
There's might be nothing wrong with the code: this is a normal error that occurs when the websocket connection is lost while running an action. The action may be being run successfully (you can check logs), the client just can't tell. Is this a very long-running action in a backgrounded tab? Is there any other reason the websocket might disconnect?
yarrichar
yarricharOP•16mo ago
Nothing is showing up in the convex logs, it's like it's not making it out The action is literally what I've pasted there - stripped everything out
ballingt
ballingt•16mo ago
oh i see, no it's a very short action
yarrichar
yarricharOP•16mo ago
Yeah 🙂 I must be doing something silly somewhere - let me triple check things
ballingt
ballingt•16mo ago
To get the error the websocket needs to be disconnecting. This could be because of another error of some kind. If moment().subtract(...).date() returns a date instead of a float then that's suspicious
yarrichar
yarricharOP•16mo ago
Ahh, cool. Let me check That didn't help First load always breaks, but if I do a code change and the page does a fast refresh then that triggers another call to the action which goes through fine Is it possible to call an action before convex is ready? Running the action from a button click always works too I might just move this to a nextjs api route since I don't really need convex for that bit. Would love to know what I'm doing wrong though I "fixed" it in a slightly cheeky way - I needed to do a useQuery in that component. Only running the action after the query has resolved, fixed the issue
ballingt
ballingt•16mo ago
If you can share your code or have time to look at this together that'd be great, sounds like a frustrating debugging experience Possibly, will check to see if I can reproduce a timing issue. Are you using auth? Poking at this today I don't see a way a race could happen, so I'd love to see the way that you create your Convex client or get your backend name to look for surprising disconnections. My guess is that your client is connecting, disconnecting, and reconnecting; it's easy to do this by accident with hooks like useEffect, or just changing component identities.

Did you find this page helpful?