Menu

1 / 3

Does AbortSignal Cancel a Node.js Database Query? 4 Drivers Tested

DEV Community: node·Shubhra Pokhariya·14 days ago
#UVbsIi7h
#devtonodejs#devto#dev#query#signal
Reading 0:00
15s threshold

I let 12 Node.js clients walk away from their database queries on a 4-connection pool. The abandoned queries kept every connection busy for about 6 seconds, and the first healthy select 1 waited 5.7 seconds behind them. Passing an AbortSignal to the query did nothing for pg, mysql2 or mariadb, and postgres.js 3.4.9 has no such option.

This is the second post in my series on cancellation in Node.js. In the first, I tested whether aborting a request stops the work behind it ( read it here ). With node-postgres it doesn't. The query ran to completion, and pg_cancel_backend was what stopped it. That left two questions. Do other drivers behave differently? And what does a pile of abandoned queries do to everyone else who shares the pool?

I built a harness to answer both, and the postgres.js results did not go the way I expected. My first postgres.js starvation run came back with four cancelled promises that never settled, and my harness threw the run away as invalid.…

Continue reading — create a free account

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