Skip to content

fix cancelled + serialize error#1044

Merged
mikasenghaas merged 3 commits intomainfrom
fix/zmq-server-silent-hang
Mar 20, 2026
Merged

fix cancelled + serialize error#1044
mikasenghaas merged 3 commits intomainfrom
fix/zmq-server-silent-hang

Conversation

@mikasenghaas
Copy link
Member

@mikasenghaas mikasenghaas commented Mar 20, 2026

Description

  • CancelledError no longer silently drops requests: Previously, if a process_request task was cancelled (e.g. client disconnect, task cancellation), the server returned without sending any ZMQ response — leaving the client hanging until the 10-hour default timeout. Now sends an error response so the client slot is freed immediately.
  • Serialization failures send fallback error response: If msgpack.packb(response.model_dump()) throws (e.g. on a malformed or huge response), the exception was unhandled and socket.send_multipart was never reached — again leaving the client hanging. Now catches serialization errors and sends a plain error response.

Type of Change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Documentation update
  • Test improvement

Testing

  • All existing tests pass when running uv run pytest locally.
  • New tests have been added to cover the changes

Checklist

  • My code follows the style guidelines of this project as outlined in AGENTS.md
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • Any dependent changes have been merged and published

Additional Notes


Note

Medium Risk
Changes error-handling in the ZMQ request/response path to avoid dropping replies; a mistake could alter client-visible behavior or mask underlying failures, but scope is limited to response generation.

Overview
Prevents ZMQ clients from hanging when a process_request task is cancelled by returning a BaseResponse error instead of silently exiting.

Hardens response sending by catching exceptions during msgpack serialization and emitting a fallback error payload, ensuring send_multipart still runs and the client receives a failure response.

Written by Cursor Bugbot for commit d26f327. This will update automatically on new commits. Configure here.

@mikasenghaas mikasenghaas marked this pull request as ready for review March 20, 2026 11:26
@mikasenghaas mikasenghaas merged commit 18a4f6a into main Mar 20, 2026
6 checks passed
Copy link

@cursor cursor bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Fix All in Cursor

Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.


except asyncio.CancelledError:
return
response = BaseResponse(success=False, error="Request was cancelled")
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Caught CancelledError re-raises at subsequent await points

High Severity

Catching asyncio.CancelledError at line 249 without calling asyncio.current_task().uncancel() leaves the task's internal cancellation flag set. The asyncio event loop will re-raise CancelledError at the next await point (await asyncio.to_thread(...) on line 272). Since CancelledError is a BaseException (not Exception) in Python 3.10+, the except Exception on line 273 won't catch it. The error propagates uncaught and the response is never sent — the exact problem this PR aims to fix.

Additional Locations (1)
Fix in Cursor Fix in Web

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants