Skip to content

Abort JoinHandle when futures are cancelled/dropped#100

Open
lukipuki wants to merge 2 commits intomainfrom
abort-task
Open

Abort JoinHandle when futures are cancelled/dropped#100
lukipuki wants to merge 2 commits intomainfrom
abort-task

Conversation

@lukipuki
Copy link
Copy Markdown
Collaborator

@lukipuki lukipuki commented May 2, 2026

Summary
This PR implements automatic task abortion for background tasks to ensure they are cleaned up when their handles are dropped. It refactors the management of read, write, processing, heartbeat, and bridge handlers to use tokio_util::task::AbortOnDropHandle.

This prevents resource leaks and ensures clean shutdowns when operations (such as connect()) are cancelled, for example by a tokio::time::timeout.

Related Issues
Fixes #88

Proposed Changes

  • Robust Task Management: Refactor ConnectedStreamApi and StreamHandle to use AbortOnDropHandle. This ensures that background tasks are aborted immediately when the API object is dropped or when a connect() future is cancelled.
  • Bridge Support: Properly manages the bridge_handle for low-level transports (like BLE), ensuring it is aborted and awaited during disconnection.
  • Dependency Update: Enabled the rt feature for tokio-util in Cargo.toml.

Checklist

  • Tests pass locally
  • Documentation updated if needed

Use the new `AbortingJoinHandle` to cancel a JoinHandle (using
`JoinHandle::abort()`) when `AbortingJoinHandle` is dropped.
@lukipuki lukipuki changed the title Abort JoinHandle when tasks are aborted Abort JoinHandle when futures are cancelled/dropped May 2, 2026
No reason to implement our own AbortingJoinHandle
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.

Stream::connect() never fails nor times out

1 participant