-
-
Notifications
You must be signed in to change notification settings - Fork 17.9k
Closed
Description
Description
File handles opened with open(file_path, "rb") are passed to HTTP requests but never closed. Each request leaks one file descriptor.
Locations
1. audio.py (line ~645)
File: backend/open_webui/routers/audio.py
r = requests.post(
url=f"{request.app.state.config.STT_OPENAI_API_BASE_URL}/audio/transcriptions",
headers=headers,
files={"file": (filename, open(file_path, "rb"))}, # never closed
data=payload,
)requests.post does not close file objects passed in files. If the request fails or the function returns early, the file descriptor leaks.
2. pipelines.py (line ~234)
File: backend/open_webui/routers/pipelines.py
form_data = aiohttp.FormData()
form_data.add_field(
"file",
open(file_path, "rb"), # never closed
filename=filename,
content_type="application/octet-stream",
)Same issue with aiohttp.FormData.
Fix
Simplest fix — use pathlib.Path.read_bytes(), which opens, reads, and closes the file in one call:
from pathlib import Path
# audio.py
r = requests.post(
url=...,
files={"file": (filename, Path(file_path).read_bytes())},
data=payload,
)
# pipelines.py
form_data = aiohttp.FormData()
form_data.add_field(
"file",
Path(file_path).read_bytes(),
filename=filename,
content_type="application/octet-stream",
)No file descriptor leak — read_bytes() handles open/close internally.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels