Menu

Post image 1
Post image 2
1 / 2
0

JavaScript Async Lifetimes: The Leak You Have and Probably Do Not Know About

DEV Community·Alex Cloudstar·26 days ago
#Z5a9Qyt8
Reading 0:00
15s threshold

Here is a production bug I have seen three times now, in three different codebases, written by three developers who all considered themselves experienced with async JavaScript. A route handler fires three parallel database queries with Promise.all . One of them hits a slow external service and times out after 30 seconds. Promise.all rejects immediately. The handler sends a 500. The caller moves on. The other two queries are still running. They are holding database connection pool slots. At a few hundred concurrent requests, the pool exhausts. Every subsequent request queues waiting for a slot. The app looks hung, but the logs show mostly successes. The fix everyone reaches for is adding a shorter timeout to the slow query. That helps but does not solve the underlying issue. When Promise.all rejects, it rejects. It does not cancel the tasks it was waiting on. Those tasks have no owner anymore.…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.

Read More