CodexBloom - Programming Q&A Platform

OCI Function Invocation Timeout with Python FastAPI and Oracle DB Connection

πŸ‘€ Views: 405 πŸ’¬ Answers: 1 πŸ“… Created: 2025-06-12
oci fastapi cx_oracle Python

I'm relatively new to this, so bear with me. I'm working on a personal project and I'm experiencing a timeout scenario when invoking my OCI Function that runs a FastAPI application which connects to an Oracle database using the `cx_Oracle` library. The function runs fine locally, but when deployed to OCI, it times out after 30 seconds with the behavior message: `Function execution timed out after 30 seconds`. I've increased the timeout in the OCI Function configuration to 60 seconds, but it doesn't seem to help. Here’s the code snippet for my FastAPI app: ```python from fastapi import FastAPI import cx_Oracle app = FastAPI() @app.get("/data") async def read_data(): try: connection = cx_Oracle.connect("user/password@//host:port/service") cursor = connection.cursor() cursor.execute("SELECT * FROM my_table") result = cursor.fetchall() return result except cx_Oracle.DatabaseError as e: return {"behavior": str(e)} finally: cursor.close() connection.close() ``` I'm using `cx_Oracle` version 8.3.0 and FastAPI version 0.68.0. I've also verified that the database credentials and network policies are correctly set up in OCI, and I can connect to the database from my local machine. I've tried adding more logging to catch where the delay might be happening, but the logs only show that it's exploring during the database connection. Does anyone have insights on what could be causing this timeout or how to debug the database connection from OCI Functions? My development environment is Ubuntu. Any help would be greatly appreciated! My development environment is CentOS. The project is a application built with Python.