Sequelize Query Cancellation Across Dialects Lacks Unified Timeout Configuration
0 reputation · 15 Feb 2020, 23:17 UTC
0 reputation · 15 Feb 2020, 23:17 UTC
Determine whether a single Sequelize configuration can both abort an in‑flight query at the database level and ensure the transaction is rolled back and the connection returned to the pool across PostgreSQL, MySQL/MariaDB, and SQL Server.
Pool.acquire only limits waiting for a connection; after checkout the query continues under the driver; PostgreSQL provides statement_timeout but other dialects expose separate timeout fields, and the documented pool options do not cover query cancellation.
Which dialect‑specific timeout option should be used for each driver to achieve consistent cancellation? Does the chosen timeout guarantee transaction rollback and connection reuse, or must additional error handling be applied? Is there a version‑stable API that abstracts this behavior?
No. Sequelize does not provide a single, version-stable configuration that cancels an in-flight query, rolls back the transaction, and returns the connection to the pool across PostgreSQL, MySQL/MariaDB, and SQL Server. pool.acquire and related pool timeouts only bound how long Sequelize waits to check out a connection; they do not cancel SQL already running.
| Dialect | Timeout option | Coverage |
|---|---|---|
| PostgreSQL | statement_timeout, typically set as a session option after checkout | All statements; a timeout aborts the whole transaction |
| SQL Server (tedious) | requestTimeout in dialectOptions, in milliseconds | Individual requests; the driver aborts the request |
| MySQL | max_execution_time | SELECT only, server-version dependent |
| MariaDB | max_statement_time | Behavior varies by server version and driver |
A timeout error does not automatically roll back a transaction or guarantee that the connection is returned for reuse. Catch the rejection, call transaction.rollback(), and let Sequelize release the connection. A timed-out connection may be unusable and may be discarded by the pool instead of returned.
SELECT 1 in the same transaction after the timeout; expect an aborted-transaction error until rollback executes.max_execution_time or max_statement_time on a SELECT to confirm the driver cancels the query and returns an error.Which statement types (SELECT only, or DML/DDL too) and which MySQL/MariaDB server versions do you need to cancel? This changes the recommendation because MySQL/MariaDB timeouts are statement-limited and version-dependent.
Assumptions and uncertainty: dialect option keys and timeout semantics depend on your exact sequelize, pg, mysql2, and tedious versions. Treat the table as a starting point, not a version-stable API, and verify it against your installed dependency tree.
Use comments to ask for clarification. Post a solution as an answer.
No question comments on this page.