Skip to content

Commit 3eee245

Browse files
Fixed bug when calling oracledb.connect_async() multiple times
concurrently.
1 parent 36c9a28 commit 3eee245

File tree

3 files changed

+84
-78
lines changed

3 files changed

+84
-78
lines changed

doc/src/release_notes.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ Thin Mode Changes
2525
``wait_timeout`` value and the connection request will not additionally be
2626
delayed by any internal network ping to the database (`issue 330
2727
<https://github.com/oracle/python-oracledb/issues/330>`__).
28+
#) Fixed bug when calling :meth:`oracledb.connect_async()` multiple times
29+
concurrently.
2830
#) Fixed bug in fetching dates with years less than 0
2931
(`issue 345 <https://github.com/oracle/python-oracledb/issues/345>`__).
3032

src/oracledb/connection.py

Lines changed: 41 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1461,47 +1461,49 @@ async def _connect(self, dsn, pool, params, kwargs):
14611461
asyncio.
14621462
"""
14631463

1464-
# mandate that thin mode is required
1465-
with driver_mode.get_manager(requested_thin_mode=True):
1466-
# determine which connection parameters to use
1467-
if params is None:
1468-
params_impl = base_impl.ConnectParamsImpl()
1469-
elif not isinstance(params, ConnectParams):
1470-
errors._raise_err(errors.ERR_INVALID_CONNECT_PARAMS)
1471-
else:
1472-
params_impl = params._impl.copy()
1473-
dsn = params_impl.process_args(dsn, kwargs, thin=True)
1474-
1475-
# see if connection is being acquired from a pool
1476-
if pool is None:
1477-
pool_impl = None
1478-
elif not isinstance(pool, pool_module.AsyncConnectionPool):
1479-
message = (
1480-
"pool must be an instance of "
1481-
"oracledb.AsyncConnectionPool"
1482-
)
1483-
raise TypeError(message)
1484-
else:
1485-
pool._verify_open()
1486-
pool_impl = pool._impl
1464+
# mandate that thin mode is required; with asyncio, only thin mode is
1465+
# supported and only one thread is executing, so the manager can be
1466+
# manipulated directly
1467+
driver_mode.manager.thin_mode = True
1468+
1469+
# determine which connection parameters to use
1470+
if params is None:
1471+
params_impl = base_impl.ConnectParamsImpl()
1472+
elif not isinstance(params, ConnectParams):
1473+
errors._raise_err(errors.ERR_INVALID_CONNECT_PARAMS)
1474+
else:
1475+
params_impl = params._impl.copy()
1476+
dsn = params_impl.process_args(dsn, kwargs, thin=True)
14871477

1488-
# create implementation object
1489-
if pool is not None:
1490-
impl = await pool_impl.acquire(params_impl)
1491-
else:
1492-
impl = thin_impl.AsyncThinConnImpl(dsn, params_impl)
1493-
await impl.connect(params_impl)
1494-
self._impl = impl
1478+
# see if connection is being acquired from a pool
1479+
if pool is None:
1480+
pool_impl = None
1481+
elif not isinstance(pool, pool_module.AsyncConnectionPool):
1482+
message = (
1483+
"pool must be an instance of oracledb.AsyncConnectionPool"
1484+
)
1485+
raise TypeError(message)
1486+
else:
1487+
pool._verify_open()
1488+
pool_impl = pool._impl
14951489

1496-
# invoke callback, if applicable
1497-
if (
1498-
impl.invoke_session_callback
1499-
and pool is not None
1500-
and pool.session_callback is not None
1501-
and callable(pool.session_callback)
1502-
):
1503-
await pool.session_callback(self, params_impl.tag)
1504-
impl.invoke_session_callback = False
1490+
# create implementation object
1491+
if pool is not None:
1492+
impl = await pool_impl.acquire(params_impl)
1493+
else:
1494+
impl = thin_impl.AsyncThinConnImpl(dsn, params_impl)
1495+
await impl.connect(params_impl)
1496+
self._impl = impl
1497+
1498+
# invoke callback, if applicable
1499+
if (
1500+
impl.invoke_session_callback
1501+
and pool is not None
1502+
and pool.session_callback is not None
1503+
and callable(pool.session_callback)
1504+
):
1505+
await pool.session_callback(self, params_impl.tag)
1506+
impl.invoke_session_callback = False
15051507

15061508
return self
15071509

utils/templates/connection.py

Lines changed: 41 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1252,47 +1252,49 @@ async def _connect(self, dsn, pool, params, kwargs):
12521252
asyncio.
12531253
"""
12541254

1255-
# mandate that thin mode is required
1256-
with driver_mode.get_manager(requested_thin_mode=True):
1257-
# determine which connection parameters to use
1258-
if params is None:
1259-
params_impl = base_impl.ConnectParamsImpl()
1260-
elif not isinstance(params, ConnectParams):
1261-
errors._raise_err(errors.ERR_INVALID_CONNECT_PARAMS)
1262-
else:
1263-
params_impl = params._impl.copy()
1264-
dsn = params_impl.process_args(dsn, kwargs, thin=True)
1265-
1266-
# see if connection is being acquired from a pool
1267-
if pool is None:
1268-
pool_impl = None
1269-
elif not isinstance(pool, pool_module.AsyncConnectionPool):
1270-
message = (
1271-
"pool must be an instance of "
1272-
"oracledb.AsyncConnectionPool"
1273-
)
1274-
raise TypeError(message)
1275-
else:
1276-
pool._verify_open()
1277-
pool_impl = pool._impl
1255+
# mandate that thin mode is required; with asyncio, only thin mode is
1256+
# supported and only one thread is executing, so the manager can be
1257+
# manipulated directly
1258+
driver_mode.manager.thin_mode = True
1259+
1260+
# determine which connection parameters to use
1261+
if params is None:
1262+
params_impl = base_impl.ConnectParamsImpl()
1263+
elif not isinstance(params, ConnectParams):
1264+
errors._raise_err(errors.ERR_INVALID_CONNECT_PARAMS)
1265+
else:
1266+
params_impl = params._impl.copy()
1267+
dsn = params_impl.process_args(dsn, kwargs, thin=True)
12781268

1279-
# create implementation object
1280-
if pool is not None:
1281-
impl = await pool_impl.acquire(params_impl)
1282-
else:
1283-
impl = thin_impl.AsyncThinConnImpl(dsn, params_impl)
1284-
await impl.connect(params_impl)
1285-
self._impl = impl
1269+
# see if connection is being acquired from a pool
1270+
if pool is None:
1271+
pool_impl = None
1272+
elif not isinstance(pool, pool_module.AsyncConnectionPool):
1273+
message = (
1274+
"pool must be an instance of oracledb.AsyncConnectionPool"
1275+
)
1276+
raise TypeError(message)
1277+
else:
1278+
pool._verify_open()
1279+
pool_impl = pool._impl
12861280

1287-
# invoke callback, if applicable
1288-
if (
1289-
impl.invoke_session_callback
1290-
and pool is not None
1291-
and pool.session_callback is not None
1292-
and callable(pool.session_callback)
1293-
):
1294-
await pool.session_callback(self, params_impl.tag)
1295-
impl.invoke_session_callback = False
1281+
# create implementation object
1282+
if pool is not None:
1283+
impl = await pool_impl.acquire(params_impl)
1284+
else:
1285+
impl = thin_impl.AsyncThinConnImpl(dsn, params_impl)
1286+
await impl.connect(params_impl)
1287+
self._impl = impl
1288+
1289+
# invoke callback, if applicable
1290+
if (
1291+
impl.invoke_session_callback
1292+
and pool is not None
1293+
and pool.session_callback is not None
1294+
and callable(pool.session_callback)
1295+
):
1296+
await pool.session_callback(self, params_impl.tag)
1297+
impl.invoke_session_callback = False
12961298

12971299
return self
12981300

0 commit comments

Comments
 (0)