sst / ion

SST v3
https://sst.dev
MIT License
1.88k stars 221 forks source link

Remix lambda (billed) duration is way too long and strangely consistent at 5 seconds #508

Closed pablote closed 3 months ago

pablote commented 3 months ago

This is very easy to reproduce, just do the "Get Started" guide for Remix, deploy to AWS, and watch Cloudwatch as you enter the site. You'll see something like this:

Screenshot 2024-06-02 at 11 49 33 PM

If you add a couple of extra routes and navigate between them, you'll see that with client-side navigation, the lambda is only returning JSON and it runs pretty fast. But the moment you refresh the browser it goes back to ~5000ms. This is a huge amount of time to be billed for every page load. Now, this doesn't match the timing observed on the browser, where I get the response from the server much earlier, but it's like the backend keeps running for a long time after already returning a response. Almost feels like there's some handle open that prevents the lambda from actually finishing, and timing out after 5s.

Back to my app where I first noticed this, I added some logging at the end of the data fetching and the end of the loader function:

Screenshot 2024-06-02 at 11 31 49 PM

If you see the timestamps, everything finished pretty fast, the browser already has a response, but then it takes an extra 5s for the lambda to actually finish, and I'm getting billed for the whole time.

thdxr commented 3 months ago

this is fixed in v0.0.411

seems like remix has a dangling promise bug somewhere but we have a workaround