Skip to content

Transactions not closing their connections #1601

Closed

Description

@causal-agent

I'm using transactions (connected to a Postgres database) and after I call commit() or rollback() on them, their connections are left open, causing a sorry, too many clients already error to happen later on in my application when I try to start more transactions.

Output from SELECT * FROM pg_stat_activity; after a transaction has run and completed:

-[ RECORD 1 ]----+--------------------------------
datid            | 1551576
datname          | listens
pid              | 12586
usesysid         | 16384
usename          | curtis
application_name | psql
client_addr      | 
client_hostname  | 
client_port      | -1
backend_start    | 2014-04-06 16:57:43.994157-04
xact_start       | 2014-04-06 16:58:19.613453-04
query_start      | 2014-04-06 16:58:19.613453-04
state_change     | 2014-04-06 16:58:19.613455-04
waiting          | f
state            | active
query            | select * from pg_stat_activity;
-[ RECORD 2 ]----+--------------------------------
datid            | 1551576
datname          | listens
pid              | 12646
usesysid         | 16384
usename          | curtis
application_name | 
client_addr      | 127.0.0.1
client_hostname  | 
client_port      | 33059
backend_start    | 2014-04-06 16:58:14.909206-04
xact_start       | 
query_start      | 2014-04-06 16:58:14.956924-04
state_change     | 2014-04-06 16:58:14.957053-04
waiting          | f
state            | idle
query            | COMMIT;

Activity

  1. mickhansen commented on Apr 7, 2014

    @mickhansen
    Contributor

    We've seen this in production, they are in fact closed, but not untill the idle timeout is reached. Connections should probably be explicitely closed on commit/rollback.

    @programble if you can provide a PR with a unit test that would be neat (would also speed up getting a fix in)

  2. miklacko commented on Apr 7, 2014

    @miklacko

    Hi,
    Same for me. After commit or rollback transaction i need to wait few seconds to close connection.
    Sometimes... in "query" column(from SELECT * FROM pg_stat_activity;) is not the "COMMIT" but some select or insert from inside of transaction.
    For example SELECT * from "Reports" where "Reports"."id" = 1474 LIMIT 1
    Please can you help? Thank you

  3. mickhansen commented on Apr 8, 2014

    @mickhansen
    Contributor

    @miklacko i'll refer you to the comment i wrote.

  4. maximeCony commented on Apr 14, 2014

    @maximeCony
    Contributor

    Hi @mickhansen, I also have the problem, I tried to reproduce the error with a test
    Uncaught error: sorry, too many clients already
    maximeCony@09bb5fa
    I hope this will help you.

  5. mickhansen commented on Apr 15, 2014

    @mickhansen
    Contributor

    @maximeCony unit tests always helps me - I'll take a look, or perhaps @sdepold can?

  6. sdepold commented on Apr 15, 2014

    @sdepold
    Member

    will check that later the day

  7. alexnaspo commented on Apr 23, 2014

    @alexnaspo

    +1
    I am having this error as well. Can I rely on transactions at this stage in development for production purposes?

  8. mickhansen commented on Apr 23, 2014

    @mickhansen
    Contributor

    @alexnaspo Not with a decent amount of concurrency going on. Transactions need to be refactored to use connection pools. Hopefully we will get a fix in soon.

    Edit: But i suppose it depends on when you plan to hit production.

  9. nisnardi commented on Apr 23, 2014

    @nisnardi

    +1 I have the same problem.

  10. added this to the milestone on Apr 27, 2014
  11. miklacko commented on Jun 10, 2014

    @miklacko

    Hi is something new about this issue?? I still having problems to use transactions because they are not closing connections.
    Thx

  12. janmeier commented on Jun 10, 2014

    @janmeier
    Member

    @miklacko More unit-tests are always welcome

  13. janmeier commented on Jun 10, 2014

    @janmeier
    Member

    But apart from that, as mick mentioned the connection management is due for a re-factor

  14. mickhansen commented on Jun 10, 2014

    @mickhansen
    Contributor

    And that re-factor has been started, but it's gonna be a little while before it's done.

  15. mickhansen commented on Jun 12, 2014

    @mickhansen
    Contributor

    Should be solved by #1892 - I would like people to try out this pull request and let me know if it solves their issue.

  16. mickhansen commented on Jun 12, 2014

    @mickhansen
    Contributor

    @maximeCony i implemented your test in a modified way (your test was broken in multiple ways) in: 3495887

  17. maximeCony commented on Jun 16, 2014

    @maximeCony
    Contributor

    @mickhansen I had to remove transactions from my project. I will reimplement them as soon as I am upgrading Sequelize (currently on 2.0.0-dev10)
    I'll let you know.
    Thanks a lot!

  18. mickhansen commented on Jun 17, 2014

    @mickhansen
    Contributor
  19. BhuvaneshwaranR commented on Oct 15, 2021

    @BhuvaneshwaranR

    Is this issue resolved?

  20. kishita101 commented on Jan 6, 2024

    @kishita101

    I am still facing the same issue!

    Error: ConnectionManager.getConnection was called after the connection manager was closed!
    server  |     at ConnectionManager.getConnection (/app/node_modules/sequelize/lib/dialects/abstract/connection-manager.js:70:13)
    server  |     at /app/node_modules/sequelize/lib/sequelize.js:305:111
    server  |     at /app/node_modules/retry-as-promised/dist/index.js:59:25
    server  |     at new Promise (<anonymous>)
    server  |     at retryAsPromised (/app/node_modules/retry-as-promised/dist/index.js:48:12)
    server  |     at Sequelize.query (/app/node_modules/sequelize/lib/sequelize.js:300:12)
    server  |     at MySQLQueryInterface.select (/app/node_modules/sequelize/lib/dialects/abstract/query-interface.js:407:33)
    server  |     at Function.findAll (/app/node_modules/sequelize/lib/model.js:1140:47)
    server  |     at processTicksAndRejections (internal/process/task_queues.js:95:5)
    server  |     at async Function.findOne (/app/node_modules/sequelize/lib/model.js:1240:12)
    
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    type: bug

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions