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

PgSQL output doesn't reopen connection on error threshold breach #68

Open
simplevoip opened this issue Jul 29, 2020 · 2 comments
Open

Comments

@simplevoip
Copy link

We've been running the PgSQL output plugin for a while in production, and occasionally it attempts to insert duplicate IDs somehow. This shouldn't be a problem for our specific application, except that these primary key conflicts increase the output plugin's error count, and when the error threshold (a hard-coded >= 10) is reached, the plugin should close & reopen the connection and clear the error count.

The problem appears to be related to the node-postgres calls being made to restart that connection. Our logs end up filling up with the following error:

Error: Client has already been connected. You cannot reuse a client.
at Client._connect (/usr/lib/node_modules/@pastash/output_pgsql/node_modules/pg/lib/client.js:92:17)
at /usr/lib/node_modules/@pastash/output_pgsql/node_modules/pg/lib/client.js:302:10
at new Promise ()
at Client.connect (/usr/lib/node_modules/@pastash/output_pgsql/node_modules/pg/lib/client.js:301:10)
at Query.callback (/usr/lib/node_modules/@pastash/output_pgsql/output_pgsql.js:103:36)
at Query.handleError (/usr/lib/node_modules/@pastash/output_pgsql/node_modules/pg/lib/query.js:138:19)
at /usr/lib/node_modules/@pastash/output_pgsql/node_modules/pg/lib/client.js:544:13
at processTicksAndRejections (internal/process/task_queues.js:79:11)

It appears that we should be spinning up a new Client() after calling end() rather than attempting pool.client.end(); pool.client.connect();: brianc/node-postgres#1352

@lmangani
Copy link
Member

lmangani commented Jul 29, 2020

Good catch! So this is where it happens. Could you try replace the pool connect with this.start and see if it reconnects properly?

                        if(insert_failures > 10) {
				insert_failures = 0;
				logger.error("too many insert failures, restarting pool");
				pool.client.end();
				this.start();
			}

@simplevoip
Copy link
Author

3|pastash_ | TypeError: this.start is not a 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

2 participants