Skip to content

fix(ai): cancel DataConn._monitor_pipes task on disconnect (#2940) - #2991

Open
CG-5228 wants to merge 1 commit into
rocketride-org:developfrom
CG-5228:fix/data-conn-monitor-pipes-shutdown
Open

CG-5228 wants to merge 1 commit into
rocketride-org:developfrom
CG-5228:fix/data-conn-monitor-pipes-shutdown

Conversation

@CG-5228

@CG-5228 CG-5228 commented Nov 4, 2026 •

Copy link
Copy Markdown

Summary

  • Track the background asyncio.create_task(self._monitor_pipes()) handle on DataConn._monitor_task and cancel/await it in DataConn.close().
  • Call await conn.close() inside DataServer.on_disconnect so the monitor task is cleanly cancelled before loop teardown.
  • Add unit tests verifying _monitor_task is cancelled and awaited when DataConn.close() is called.

Fixes #2940

Summary by CodeRabbit

  • Bug Fixes
    • Improved cleanup of data connections when they disconnect, including when accepting a connection fails.
    • Pending requests are cleared and shutdown state is reset more reliably.

@github-actions

github-actions Bot commented Nov 4, 2026

Copy link
Copy Markdown
Contributor
🤖 Internal: Discord sync marker

Auto-managed by the Discord notification workflow. Stores the linked Discord message ID and forum thread ID. Do not edit or delete.

@coderabbitai

coderabbitai Bot commented Nov 4, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

No actionable comments were generated in the recent review.

Walkthrough

DataConn now stops its pipe monitor during disconnection. DataServer runs connection and EaaS cleanup after transport acceptance, including when acceptance raises an exception.

Changes: Data connection cleanup

Layer / File(s) Summary
Stop the DataConn monitor
packages/ai/src/ai/modules/data/data_conn.py
Disconnection invokes disconnect(). That method handles missing shutdown or pipe state, awaits the monitor task while suppressing cancellation, and returns when no pipes remain.
Run cleanup after transport acceptance
packages/ai/src/ai/modules/data/data_server.py, packages/ai/tests/ai/modules/data/test_data_conn.py
The server awaits connection cleanup and runs cleanup in a finally block. Tests cover monitor shutdown and EaaS state reset when transport acceptance raises; the exception propagates.

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Bug fix · Severity of issue fixed: Low

Possibly related issues

  • Issue 2940 describes a pending DataConn._monitor_pipes task after the data connection closes. This change stops and awaits the monitor task during connection cleanup.

Suggested labels: module:ai, tests

Suggested reviewers: jmaionchi, rod-christensen, dsapandora

Merge Risk: Minimal · up to 904ac

This change stops the data connection's pipe monitor on disconnect and runs cleanup even when accepting the transport fails, which addresses the pending-task warning at shutdown. No concrete merge-blocking risk remains after review.

Pre-merge checks: Passed 4 · Inconclusive 1

Failed Failed checks: 1 inconclusive

Check name Status Explanation Resolution
Title check Inconclusive The title names a cancellation of the DataConn._monitor_pipes task on disconnect, but the raw summary does not describe that change. The summary describes disconnect() tolerating missing state, awaiti… Confirm that the diff cancels DataConn._monitor_pipes on disconnect. The summary and objectives use different names and calls (disconnect() versus close(), and _monitor_task). Align the title with the actual mechanism. Also confirm the issu…
Passed Passed checks: 4 passed
Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Linked Issues check Passed Issue #2940 requires the DataConn._monitor_pipes task to finish during task shutdown. DataConn.on_disconnected() now calls disconnect(). DataServer.listen() calls its disconnection handler in a finall…
Out of Scope Changes check Passed The changes stay within issue #2940. They add connection cleanup, ensure cleanup runs when transport acceptance raises, reset the EaaS connection state, and test these shutdown paths. These changes di…
Docstring Coverage Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentat…
Full details: Linked Issues check

Explanation

Issue #2940 requires the DataConn._monitor_pipes task to finish during task shutdown. DataConn.on_disconnected() now calls disconnect(). DataServer.listen() calls its disconnection handler in a finally block, including transport-accept failures. disconnect() sets _shutdown_event and awaits _monitor_task. The added tests verify that the monitor task finishes on both shutdown paths.

Full details: Out of Scope Changes check

Explanation

The changes stay within issue #2940. They add connection cleanup, ensure cleanup runs when transport acceptance raises, reset the EaaS connection state, and test these shutdown paths. These changes directly support reliable monitor-task shutdown.

Full details: Docstring Coverage

Explanation

Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentation-only edits and deletions within surviving functions are included; unchanged diff context and fully deleted functions are excluded. Analyzed 4 functions across 3 files.

Full details: Title check

Explanation

The title names a cancellation of the DataConn._monitor_pipes task on disconnect, but the raw summary does not describe that change. The summary describes disconnect() tolerating missing state, awaiting the monitor task with cancellation suppressed, and try/finally handling in DataServer.listen. The objectives describe tracking the task in _monitor_task and canceling it in close(). The title's subject matches the objectives and linked issue #2940, but the code summary does not show the cancel-on-disconnect behavior being added. The title is also tied to a different issue number than the PR objectives, which reference #2991.

Resolution

Confirm that the diff cancels DataConn._monitor_pipes on disconnect. The summary and objectives use different names and calls (disconnect() versus close(), and _monitor_task). Align the title with the actual mechanism. Also confirm the issue number, because the title cites #2940 while the objectives cite PR #2991.

Finishing Touches
Generate unit tests (beta)
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share
Recent review info
Run configuration
Commits

Reviewing files that changed from the base of the PR and between 6560ead and 904ac72.

Files selected for processing: 3
  • packages/ai/src/ai/modules/data/data_conn.py
  • packages/ai/src/ai/modules/data/data_server.py
  • packages/ai/tests/ai/modules/data/test_data_conn.py

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 8 remain after this review.

This branch has not been deployed

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

Labels

module:ai AI/ML modules tests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Task shutdown logs "Task was destroyed but it is pending!" for DataConn._monitor_pipes

1 participant