vrogier / ocilib

OCILIB (C and C++ Drivers for Oracle) - Open source C and C++ library for accessing Oracle databases
http://www.ocilib.net
Apache License 2.0
325 stars 119 forks source link

Pool connection is never released (C++) #355

Open gix opened 1 year ago

gix commented 1 year ago

The following code hangs in OCISessionGet in the third iteration:

ocilib::Environment::Initialize(ocilib::Environment::Threaded);
ocilib::Pool connPool(db, user, password, ocilib::Pool::SessionPool, 1, 2);

for (int i = 0; i < 3; ++i) {
    ocilib::Connection connection = connPool.GetConnection();
}

The connections are never released to the pool. As far as I can tell, the Connection object is created as transient, and so the HandleDeleter is never called. But maybe I'm doing something wrong.

MagicXran commented 1 year ago

Brother, write your own thread pool. The performance of the built-in thread pool feels too low or always error-prone. I have given up using it. Write your own thread pool.

vrogier commented 7 months ago

Hi,

The code hangs in the 3rd iteration as by default, if the pool is exhausted, requesting a new connection blocks until one is available. This is expected behavior. You can change that behavior by using OCI_PoolSetNoWait().

Regards,

Vincent

gix commented 7 months ago

The code hangs in the 3rd iteration as by default, if the pool is exhausted, requesting a new connection blocks until one is available.

That's not the issue I was describing. The problem is that ~Connection does not release the connection back to the pool. Sample code using a connection also seems to rely on the destructor. Is it required to manually close the connection? If so, the documentation of Close should be clarified and state that a pooled connection is returned and not really closed.

vrogier commented 7 months ago

Indeed, I missed that point.

I will investigate.

Regards,

Vincent.

vrogier commented 7 months ago

Hi,

This is a bug introduced by commit 8ad2fa43c8b9f5089fa3b26aa96f16b0f2eb20e5 in v4.7.5. It is now fixed in v4.7.7 dev branch.

Regards,

Vincent