Skip to content

[P6.6.3] Fix tasks.py connection leak-on-exception + unreferenced fire-and-forget tasks #650

Description

@frankbria

Problem

Two low-severity robustness issues:

  1. Connection leak on exception in several tasks.py read paths: they open get_db_connection and call conn.close() without try/finally. An exception between open and close leaks a connection (holding a read lock). Write paths already use try/finally correctly.
  2. Fire-and-forget tasks without strong references can be garbage-collected mid-flight (asyncio keeps only a weak reference).

Evidence

  • codeframe/core/tasks.pytasks.get (171-183) and reads at 290, 628, 672, 719, 745, 771 lack try/finally
  • codeframe/core/tasks.py:515loop.create_task(_safe_close_issue(...)) with no retained reference/done-callback
  • codeframe/notifications/webhook.py:371asyncio.create_task in send_blocker_notification_background with no reference and no no-loop fallback (appears unused; blockers.py uses the safe send_event_background at webhook.py:323, which does it correctly with add_done_callback)

Fix

  • Wrap the tasks.py reads in try/finally (or use a context manager).
  • Retain references / add add_done_callback to the fire-and-forget tasks, mirroring send_event_background. Remove or fix the apparently-unused send_blocker_notification_background.

Acceptance criteria

  • All tasks.py DB reads release the connection on exception.
  • Fire-and-forget tasks are retained until completion.

Source: release-readiness audit 2026-06-13 (backend agent).

Metadata

Metadata

Assignees

No one assigned

    Labels

    P2-medium-betaMedium priority - nice to have for betaphase-6.6Phase 6.6: Backend robustness (post-beta-tag)

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions