loopback-connector-postgresql icon indicating copy to clipboard operation
loopback-connector-postgresql copied to clipboard

Release called on client which has already been released to the pool

Open kyle-apex opened this issue 3 years ago • 2 comments

Steps to reproduce

  1. Use loopback-connector-postgresql 5.5.0 (5.4.0 does not exhibit this issue)
  2. Commit a transaction with an error (ex: unique key violation)
  3. Rollback the transaction

Current Behavior

Calling transaction.commit and subsequently transaction.rollback if there is a commit error results in:

The following error from pg-pool in the rollback is uncaught and crashes the server: Release called on client which has already been released to the pool

I would expect the error to be caught (perhaps in PostgreSQL.prototype.releaseConnection?) and passed along without crashing the server

kyle-apex avatar Feb 22 '22 14:02 kyle-apex

For others searching for this error, this override is getting me around this issue for now:

dataSource.connector.releaseConnection = function (connection, err) {
		if (typeof connection.autorelease === 'function') {
			connection.txId = null;
			connection.autorelease(err);
			connection.autorelease = null;
		} else {
			try {
				connection.release();
			} catch (err) {}
		}
	};

kyle-apex avatar Feb 23 '22 21:02 kyle-apex

Hello, Thank you for your contribution.

I got the same error, in my case I applied the following solution.

loopback-connector-postgresql/lib/transaction.js

image

marciocorrrea avatar Jun 05 '23 18:06 marciocorrrea