I’ve built a light-weight queue management service using Google Firestore and Netlify’s serverless functions.
There’s a function called “queue_next.js” that checks whether we can place the next order, and if we can, it places an order. The last step should be calling itself so the queue continues to be processed. That last step – calling itself via Axios – is called asynchronously, but not using await so the current function can return and just spawn itself again.
When developing locally it’s working like a charm: an order gets placed, the queue processes the next job up, and calls itself at the last second right before returning the previous result. No timeout, no problem.
When deployed on Netlify in production, however, it’s very inconsistent. Sometime the recursive call makes it’s way through once or more times, sometimes it just stalls completely. There’s nothing in my logs that shows any issues and I’m struggling to figure it out.
Ok, so to help anyone in future experiencing the same thing, I got around this by introducing a delay after making a recursive request.
In my application, I have a wrapper function that either calls a netlify function directly (in dev environment) or makes a fetch request to the function (in production). I now await this wrapper function, and add a delay after the fetch (which is not awaited), and lambda-lambda invocations now seem to be working. This is analogous to adding an await Promise.resolve() after the Axios.get(...) call in the OP’s example.