Skip to content

fix(api): close base64 file lookup sessions#36308

Merged
asukaminato0721 merged 2 commits into
langgenius:mainfrom
escape0707:fix/base64-service-session-leaks
May 18, 2026
Merged

fix(api): close base64 file lookup sessions#36308
asukaminato0721 merged 2 commits into
langgenius:mainfrom
escape0707:fix/base64-service-session-leaks

Conversation

@escape0707
Copy link
Copy Markdown
Contributor

@escape0707 escape0707 commented May 18, 2026

Summary

Part of #32454 (comment).

Close the private SQLAlchemy sessions created by AttachmentService.get_file_base64() and FileService.get_file_base64().

Both methods return a plain base64 string, not ORM objects or session-owned state. The caller never receives the session and cannot manage its lifetime, so the method should release the session after reading the needed UploadFile.key.

Why

Leaving these private sessions open can leave idle transactions around, consume DB resources, and block cleanup or DDL that needs stronger table locks.

This keeps the observable behavior the same: read the upload file row, copy the storage key, load bytes from storage, and return the base64-encoded string.

Validation

  • uv run --project api ruff check api/services/attachment_service.py api/services/file_service.py
  • uv run --project api python -m compileall -q api/services/attachment_service.py api/services/file_service.py

@escape0707 escape0707 requested a review from QuantumGhost as a code owner May 18, 2026 05:59
@dosubot dosubot Bot added the size:S This PR changes 10-29 lines, ignoring generated files. label May 18, 2026
@github-actions
Copy link
Copy Markdown
Contributor

Pyrefly Type Coverage

Metric Base PR Delta
Type coverage 0.00% 43.69% +43.69%
Strict coverage 0.00% 43.22% +43.22%
Typed symbols 0 22,134 +22,134
Untyped symbols 0 28,840 +28,840
Modules 0 2558 +2,558

@dosubot dosubot Bot added the lgtm This PR has been approved by a maintainer label May 18, 2026
@asukaminato0721 asukaminato0721 enabled auto-merge May 18, 2026 06:37
@asukaminato0721 asukaminato0721 added this pull request to the merge queue May 18, 2026
Merged via the queue into langgenius:main with commit c076869 May 18, 2026
27 checks passed
@escape0707 escape0707 deleted the fix/base64-service-session-leaks branch May 18, 2026 07:40
@escape0707 escape0707 mentioned this pull request May 18, 2026
5 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

lgtm This PR has been approved by a maintainer size:S This PR changes 10-29 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants