Opened 9 minutes ago

#37563 assigned Bug

Oracle connection pool leaks unused pools during concurrent initialization

Reported by: Patel Namraa Owned by: Patel Namraa
Component: Database layer (models, ORM) Version: dev
Severity: Low Keywords:
Cc: Patel Namraa Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

The Oracle database backend can leak connection pools when multiple threads access the pool property concurrently during initialization.

In django/db/backends/oracle/base.py, the pool property checks whether a pool exists in _connection_pools, creates one using Database.create_pool(), and registers it using setdefault().

If two threads access the property simultaneously, both can pass the initial membership check and independently create connection pools for the same pool key. Although setdefault() ensures that only one pool is registered, the pool created by the losing thread is discarded without being closed.

Unlike the PostgreSQL backend, which initializes its connection pool with open=False to avoid opening resources before registration, the Oracle backend creates its pool immediately. Consequently, the discarded pool may retain database sessions and other resources.

Steps to reproduce:

  1. Configure the Oracle backend with connection pooling enabled.
  2. Ensure that the connection pool has not yet been initialized.
  3. Have two threads access the pool property concurrently.
  4. Synchronize the threads so that both pass the initial dictionary membership check before either registers its pool.

Both threads can then create separate pool instances, but only one is retained in _connection_pools.

Expected behavior:

Concurrent initialization should not leave unused connection pools open. Any pool created but not registered should be properly closed.

Actual behavior:

The pool created by the losing thread is discarded without being explicitly closed, potentially leaking database sessions and other resources.

The PostgreSQL backend already avoids this issue by creating its pool with open=False, as documented in its initialization code.

This issue concerns concurrent connection-pool initialization within a process and is separate from connection-pool behavior across process forks.

Change History (0)

Note: See TracTickets for help on using tickets.
Back to Top