-
-
Notifications
You must be signed in to change notification settings - Fork 34
pg-pool force closing fastify instance #168
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
Comments
Thanks for reporting! Would you like to send a Pull Request to address this issue? Remember to add unit tests. |
I would like to, but I am not sure how to test it reliably. Perhaps someone else has better idea to do it. The bug itself can be done by adding the EventHandler after creating the pool. This way, Line 90 in ce90bc6
const pool = new pg.Pool(options)
pool.on('connect', (client) => {
client.on('error', (err) => {
console.error(err)
})
})
pool.on('error', (err) => {
console.error(err)
}) |
Adding a few log lines would be perfect. |
In this case I would try |
How about using a simpler solution? 'use strict'
const net = require('node:net');
const addrRegex = /^(([a-zA-Z\-\.0-9]+):)?([0-9]{1,5})$/;
class SocketProxy {
#connection = null;
#from = null;
#to = null;
constructor(from, to) {
this.#from = addrRegex.exec(from);
this.#to = addrRegex.exec(to);
}
start() {
if (this.#connection) return Promise.resolve();
return new Promise((resolve, reject) => {
try {
this.#connection = net.createServer(from => {
const to = net.createConnection({
host: this.#to[2],
port: this.#to[3]
});
from.pipe(to);
to.pipe(from);
}).listen(this.#from[3], this.#from[2], () => {
resolve();
});
} catch (err) {
this.#connection = null;
reject(err);
}
})
}
stop() {
this.#connection.close();
this.#connection = null;
}
}
// Example usage to forward requests from port 8080 to 3000
// node ./test/socket-proxy.js 8080 3000
const proxy = new SocketProxy(process.argv[2], process.argv[3]);
proxy.start().then(() => {
console.log('Proxy started')
console.log('Shutting down in 5 seconds')
setTimeout(() => {
proxy.stop();
}, 5000)
}) So a test would consist of following steps:
|
Prerequisites
Fastify version
4.x.x
Plugin version
5.2.2
Node.js version
18.x
Operating system
Linux
Operating system version (i.e. 20.04, 11.3, 10)
22.04
Description
Hi, I just found out this weird behavior about
pg-pool
and it turned out a known issue on its repo.When we shutdown/restart PostgreSQL instance, this module will force close our Fastify app! As my understanding, this happens due to lack of error handler in
pg-pool
, resulting unexpected termination event when we wrap the query logic using try catch. Due to my poor explanation, please read this issue: brianc/node-postgres#2439.Steps to Reproduce
Expected Behavior
No response
The text was updated successfully, but these errors were encountered: