BB
BB2mo ago

"Connection lost while action was in flight" Error

Hi all, I'm having an issue with handling large API responses in Convex. The endpoint returns responses up to 150MB in size. The request works fine via curl, but fails when i run the action from the Convex console with: "Connection lost while action was in flight" Would appreciate any guidance on best practices for handling large API responses in Convex, or alternative approaches. Thanks
6 Replies
Convex Bot
Convex Bot2mo 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!
ballingt
ballingt2mo ago
Is this in a Convex action? Are streaming the response? As a quick fix you could try making it a Node.js ("use node") action, but if you can stream the API response this should be no problem in a normal Convex action Sorry about the poor error message, would be nice to improve this
BB
BBOP2mo ago
Hey Tom, thanks for the quick response Yeah it's a Convex Action and I'm already using "use node". See image attached. unfortunately, the provider doesn't support streaming. Any other suggestions or am i missing something?
No description
ballingt
ballingt2mo ago
@BB what are you doing with the response? Is it a big file, a big blob of JSON, something else? Sounds like you're hitting the memory limits in the "use node" environment. In a sense any HTTP response can be streamed, it doesn't require support from the provider. Instead of calling .json() or .text() on the response, read it a chunk at a time and shuffle it off somewhere, e.g. to a Convex file storage URL. Unfortunately some file types are more difficult to use in a streamed way, e.g. json. If it's an image or a video this should work
BB
BBOP2mo ago
@ballingt Its a big blob of JSON. Through CURL the exact same response is roughly 115mb
ballingt
ballingt2mo ago
OK that's tough, and do you need the whole thing? Or just a little piece? You could use something like https://www.npmjs.com/package/@streamparser/json to keep the memory requirements down but for now there might not be a good solution here, I don't think you get enough memory to work with this in AWS Lambda actions or Convex actions.

Did you find this page helpful?