Skip to content

v4.2.1

Choose a tag to compare

@github-actions github-actions released this 18 Aug 10:30
· 16 commits to master since this release

Fixed

  • query.createEntity leaked a pooled connection on every failed insert.
    When no transaction was passed it opened one, and finished it only on the happy
    path — there was no rollback anywhere in the helper. A rejected save() (a
    unique or foreign-key violation, a NOT NULL, an invalid enum) unwound past the
    commit and left the transaction open.

    In sequelize 6 a pooled connection is bound to the Transaction and only
    commit() or rollback() hands it back, so nothing released it: pool.max
    failed inserts — 5 by default — exhausted the pool, after which every query in
    the process failed with SequelizeConnectionAcquireTimeoutError until it was
    restarted. On the database side the backend sat in
    idle in transaction (aborted) indefinitely.

    Ownership is now all-or-nothing, decided by a single flag used for both the
    commit and the rollback so the two cannot select different sets of calls. Only
    the call that opened the transaction finishes it; a caller-supplied transaction
    and the nested relation creates that inherit it are untouched, exactly as
    before. A rollback that fails is swallowed so it cannot replace the error that
    caused it.

    Anyone who cannot upgrade can own the lifecycle from outside, which closes the
    leak with no dependency change:

    const entity = await Model.sequelize!.transaction(transaction =>
        createEntity<T, I>(Model, data, fields, transaction),
    );

About

@imqueue/pg-sequelize turns a query described as data — filters, paging, ordering and the requested fields — into one efficient Sequelize statement, with database views as models and the Postgres index options Sequelize cannot express. Part of the @imqueue framework for Node.js & TypeScript microservices.