Error: Connection lost while action was in flight
I've just started to get the following error:
Not sure what's causing it. Pretty sure I'm doing the right thing. Functions say they're ready / deployed ok.
React code:
Convex code:
8 Replies
Other functions are fine
I've tried renaming both the file, and the individual function
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?
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
oh i see, no it's a very short action
Yeah 🙂
I must be doing something silly somewhere - let me triple check things
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
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
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.