Async database pool does not return connections · Issue #285 · oracle/python-oracledb (original) (raw)

  1. What versions are you using?
    oracledb 2.0.1

Give your database version.
Oracle Database 19

Also run Python and show the output [...]
platform.platform: Linux-5.15.133.1-microsoft-standard-WSL2-x86_64-with-glibc2.36
sys.maxsize > 2**32: True
platform.python_version: 3.12.1
oracledb.version: 2.0.1

  1. Is it an error or a hang or a crash?
    Hang - oracledb.create_pool_async() does not return connection.
  2. What error(s) or behavior you are seeing?
    There's no error, application does not return connection and does not continue in that function.
    I'm using fastapi - that connection does not respond with anything, while app overall remains functional.
  3. Does your application call init_oracle_client()?
    No.
  4. Include a runnable Python script that shows the problem.
from os import getenv
from typing import Any

import fastapi
import oracledb

dbpool = oracledb.create_pool_async(
    user=getenv("db_user"),
    password=getenv("db_password"),
    port=getenv("db_port", "1521"),
    service_name=getenv("db_service"),
    host=getenv("db_host"),
    min=0,
    max=3,
    increment=1,
)

app = fastapi.FastAPI()
@app.get("/test")
async def testpoint() -> Any:
    print("Starting test")
    async with dbpool.acquire() as con:
        print("DB aquired!")
        with con.cursor() as cursor:
            print("Got cursor!")
            await cursor.exeucte("SELECT SYSDATE FROM DUAL")
            d = await cursor.fetchone()
            return d


@app.get("/test2")
async def testpoint2() -> Any:
    print("Starting test")
    async with oracledb.connect_async(
        user=getenv("db_user"),
        password=getenv("db_password"),
        port=getenv("db_port", "1521"),
        service_name=getenv("db_service"),
        host=getenv("db_host"),
    ) as con:
        print("DB aquired!")
        with con.cursor() as cursor:
            print("Got cursor!")
            await cursor.execute("SELECT SYSDATE FROM DUAL")
            d = await cursor.fetchone()
            return d

/test endpoint hangs while /test2 returns successfully.

My environment is docker container generated from following test dockerfile:

FROM python:3.12

WORKDIR /app/

COPY api/requirements.txt /app/requirements.txt
RUN python3 -m venv .venv && \
    /app/.venv/bin/pip3 install -r requirements.txt

COPY api/ /app/api/

EXPOSE 8000
CMD ["/app/.venv/bin/uvicorn", "bslapi:app", "--host", "0.0.0.0", "--port", "8000", "--proxy-headers"]

and requirements.txt:

annotated-types==0.6.0
anyio==4.2.0
cffi==1.16.0
click==8.1.7
colorama==0.4.6
cryptography==42.0.0
fastapi==0.109.0
h11==0.14.0
idna==3.6
oracledb==2.0.1
pycparser==2.21
pydantic==2.5.3
pydantic_core==2.14.6
sniffio==1.3.0
starlette==0.35.1
typing_extensions==4.9.0
uvicorn==0.27.0