- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-06-2026 12:55 AM
Problem Statement:
We are running a Data App on Databricks that uses Next.js (frontend) and FastAPI (backend). The backend calls a Databricks Agent (AgentBricks) via a serving endpoint, which typically needs ~1 minute to return a response. However, any request that takes > ~30 seconds results in:
Error: socket hang up { code: 'ECONNRESET' }
This happens consistently and before the Agent finishes processing.
What We Are Trying To Do ::
We’re simply trying to display the agent’s response in the frontend. The frontend makes a request:
Next.js → FastAPI → Databricks AgentBricks endpoint → FastAPI → Next.js
The expectation is that long-running agent responses (45–60 sec) should return normally through the API chain.
What We Tried ::
1. Route timeout configuration in Next.js
Set long server execution time:
export const maxDuration = 300;
export const runtime = "nodejs";
Configures OK, but Next.js still disconnects at ~30 seconds.
2. FastAPI timeout controls
Set timeout in OpenAI/DBR client to 300s:
ws_openai_client = AsyncOpenAI(
api_key=DATABRICKS_PAT_TOKEN,
base_url=BASE_URL + "/serving-endpoints",
timeout=300.0
)
FastAPI is NOT timing out, meaning the reset occurs before the Python layer gets a chance to respond.
3. Artificial delay test
To isolate the issue, we added a 60-second sleep:
@app.post("/api/demo/alerts")
def get_alert_data(payload):
time.sleep(60)
return {...}
Result: Next.js → FastAPI request still dies at ~30 seconds Confirms the problem is NOT related to the agent or Databricks model serving.
4. Simplified Agent Prompt:
A lightweight prompt that finishes < 30 seconds works fine.
Confirms timeout threshold is the limiting factor.
Observation:
The request is being terminated before FastAPI finishes processing and before the Databricks agent responds. FastAPI continues running normally in the background, which means the timeout is happening upstream of the Python backend.
- Labels:
-
Workflows