Skip to content

fix(routing): isinstance(result, Exception) misses asyncio.CancelledError -- appends to docs list causing AttributeError #284

Closed

Description

@piyushmakhija28

Summary

asyncio.CancelledError is a BaseException (not Exception) in Python 3.8+. With return_exceptions=True in asyncio.gather, a cancelled _fetch_doc coroutine returns a CancelledError as the result value. The check isinstance(result, Exception) at routing.py:113 returns False for CancelledError. It is also not None, so docs.append(result) runs, appending the exception object to the docs list. Then sum(d.total_pages for d in docs) raises AttributeError: 'CancelledError' object has no attribute 'total_pages'.

Root cause

Fix #251 changed to asyncio.gather(..., return_exceptions=True) but used isinstance(result, Exception) which does not cover BaseException subclasses.

Fix

backend/app/api/routing.py line 113: change check to isinstance(result, BaseException) to also catch CancelledError, KeyboardInterrupt, and SystemExit.

Impact

Any client disconnect or outer task cancellation during multi-doc routing crashes with AttributeError instead of propagating a clean CancellationError.

Activity

  1. added
    bugSomething isn't working
    priority: highData loss, security, or major correctness bug
    code-reviewFound via automated code review
    on Jun 21, 2026
  2. piyushmakhija28 commented on Jun 21, 2026

    @piyushmakhija28
    ContributorAuthor

    Fixed in PR #280 (Sprint R3/R4: fix(sprint-r3): root-cause fixes for all 39 bugs from code review round 3 + Sprint R4 round 4)

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

    bugSomething isn't workingcode-reviewFound via automated code reviewpriority: highData loss, security, or major correctness bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions