dev.to | 📄 原文链接 | 2026-11-03 收录

AbortSignal 能取消 Node.js 的数据库查询吗:五个驱动实测

来源:dev.to — 2026-11-02

📋 概述

作者用 4 条连接的连接池,让 12 个 Node.js 客户端中途放弃查询。被放弃的查询仍然占满连接约 6 秒,之后第一个健康的 select 1 排了 5.7 秒才拿到结果。在测的五个驱动版本里,只有 postgres.js 4.0.0 会读取查询上的 AbortSignal,pg、mysql2、mariadb 和 postgres.js 3.4.9 都不理会;要真正停掉前者,得调用 pg_cancel_backend。

🔑 核心要点

💡 金句

“Passing an AbortSignal to the query did nothing for pg, mysql2 or mariadb”
译:把 AbortSignal 传给查询,对 pg、mysql2 和 mariadb 毫无作用。
← 返回 dev.to 首页