Skip to content

bug: File descriptor leak in audio.py and pipelines.py — open() without close #21411

Closed

Description

@ashm-dev

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.

Activity

  1. tjbck commented on Feb 15, 2026

    @tjbck
    Contributor

    Addressed in dev!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      Sponsor
      SponsoredKunjungi sekarang
      Promo