Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Keep connection pool alive #108

Open
negreanucalin opened this issue Dec 15, 2022 · 1 comment
Open

Keep connection pool alive #108

negreanucalin opened this issue Dec 15, 2022 · 1 comment

Comments

@negreanucalin
Copy link

negreanucalin commented Dec 15, 2022

I have made an express server and noticed that when the Pool is not being used for ~30 minutes an error spring up:

this.pool = new Pool({
    max: process.env.V_POOL_SIZE,
    idleTimeoutMillis: 0,
    connectionTimeoutMillis:0,
    allowExitOnIdle:false,
    host
});

Stack trace

/usr/src/app/node_modules/vertica-nodejs/lib/client.js:203
const error = this._ending ? new Error('Connection terminated') : new Error('Connection terminated unexpectedly')
                                                                        ^
Error: Connection terminated unexpectedly
    at Connection.<anonymous> (/usr/src/app/node_modules/vertica-nodejs/lib/client.js:203:73)
    at Object.onceWrapper (node:events:627:28)
    at Connection.emit (node:events:513:28)
    at Connection.emit (node:domain:489:12)
    at Socket.<anonymous> (/usr/src/app/node_modules/vertica-nodejs/lib/connection.js:181:12)
    at Socket.emit (node:events:525:35)
    at Socket.emit (node:domain:489:12)
    at endReadableNT (node:internal/streams/readable:1358:12)
    at processTicksAndRejections (node:internal/process/task_queues:83:21)

Is there a way to prevent this? (listen to an event and reconnect, disable auto-closing connections or catch and reconnect)

Dependencies:

    "@types/express": "^4.17.15",
    "@types/jest": "^29.2.1",
    "@types/node": "^18.11.9",
    "@types/pg-copy-streams": "^1.2.1",
    "date-fns": "^2.29.3",
    "dotenv": "^16.0.3",
    "express": "^4.18.2",
    "jest": "^29.2.2",
    "kafkajs": "^2.2.3",
    "logform": "^2.4.2",
    "moment": "^2.29.4",
    "mysql2": "^2.3.3",
    "nodemon": "^2.0.20",
    "pg-copy-streams": "^6.0.4",
    "ts-command-line-args": "^2.3.1",
    "ts-jest": "^29.0.3",
    "ts-node": "^10.9.1",
    "typescript": "^4.8.4",
    "vertica-nodejs": "^1.0.1",
    "winston": "^3.8.2"

Versions
Node v16.19.0
Vertica 11

@negreanucalin
Copy link
Author

negreanucalin commented Dec 16, 2022

Found a bit of a dirty fix:

process.on('uncaughtException', async (err ) => {
    if (err.message === 'Connection terminated unexpectedly') {
        console.log(`Restart vertica connection`)
        await verticaCon.disconnect(); // I'm calling the done() method from pool.connect()
        await verticaCon.connect();    // I'm calling this.pool.connect(err: any, client: any, done: Function) => {})
    }
})

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant