Giter Club home page Giter Club logo

Comments (5)

jonaskello avatar jonaskello commented on June 22, 2024

Same problem with trying to create an existing database. My expectation would be that the program should crash with non-zero exit code in these cases but it does not exit. I guess more error handling is needed for some promises.

$ ts-node scripts/create-db.ts
Unhandled rejection error: database "XXX" already exists
    at Connection.parseE (C:\code\XXX\diaq-app\node_modules\pg\lib\connection.js:567:11)
    at Connection.parseMessage (C:\code\XXX\diaq-app\node_modules\pg\lib\connection.js:391:17)
    at Socket.<anonymous> (C:\code\XXX\diaq-app\node_modules\pg\lib\connection.js:129:22)
    at emitOne (events.js:115:13)
    at Socket.emit (events.js:210:7)
    at addChunk (_stream_readable.js:252:12)
    at readableAddChunk (_stream_readable.js:239:11)
    at Socket.Readable.push (_stream_readable.js:197:10)
    at TCP.onread (net.js:588:20)

from knex-db-manager.

elhigu avatar elhigu commented on June 22, 2024

There are db connections left open, even when some queries fail. You need to add error handling and call https://vincit.github.io/knex-db-manager/#close and maybe https://vincit.github.io/knex-db-manager/#closeKnex to close connections (the same way that you need to call knex.destroy() when exitting app that has been using knex and has open connections in pool).

Connections cannot be closed automatically on error, because you actually might like to keep doing queries even when there has been an error.

from knex-db-manager.

jonaskello avatar jonaskello commented on June 22, 2024

Yes, you are correct. So I tried this, and it prints the closing messages but does not exit. Maybe I am doing something else wrong...

dbManager.createDb()
  .catch((e) => {
    console.log(`Error occured when creating database: ${e}`);
    dbManager.close().then(() => console.log("closed connection 1"));
    dbManager.closeKnex().then(() => console.log("closed connection 2"));
  });
Error occured when creating database: error: database "XXX" already exists
closed connection 2
closed connection 1

from knex-db-manager.

jonaskello avatar jonaskello commented on June 22, 2024

It seems this is more of a knex issue. I can reproduce using a simple Knex instance, doing a .raw() call and then calling knex.destory(). It still does not exit. Seems like the same problem as in this comment.

from knex-db-manager.

elhigu avatar elhigu commented on June 22, 2024

I'll check out if I can reproduce this with knex and report the error (+ maybe also fix it).

from knex-db-manager.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.