l2cap: Resolve teardown hang on disconnect collision or abort#937
Open
uier wants to merge 3 commits into
Open
Conversation
da093ad to
ab024b9
Compare
…ze and setting asyncio_mode
ab024b9 to
5464d43
Compare
zxzxwu
reviewed
Jun 16, 2026
|
|
||
| def abort(self) -> None: | ||
| if self.state == self.State.CONNECTED: | ||
| if self.state == self.State.CONNECTED or self.state == self.State.DISCONNECTING: |
Collaborator
There was a problem hiding this comment.
Suggested change
| if self.state == self.State.CONNECTED or self.state == self.State.DISCONNECTING: | |
| if self.state in (self.State.CONNECTED, self.State.DISCONNECTING): |
Comment on lines
+2899
to
+2902
| le_connection_channels = self.le_coc_channels.get(channel.connection.handle) | ||
| if le_connection_channels: | ||
| if le_connection_channels.get(channel.destination_cid) is channel: | ||
| del le_connection_channels[channel.destination_cid] |
Collaborator
There was a problem hiding this comment.
Suggested change
| le_connection_channels = self.le_coc_channels.get(channel.connection.handle) | |
| if le_connection_channels: | |
| if le_connection_channels.get(channel.destination_cid) is channel: | |
| del le_connection_channels[channel.destination_cid] | |
| self.le_coc_channels.pop(channel.connection.handle, None) |
Collaborator
Author
There was a problem hiding this comment.
did you mean:
le_connection_channels = self.le_coc_channels.get(channel.connection.handle)
if le_connection_channels:
self.le_coc_channels.pop(channel.connection.handle, None)or you intend to remove the whole channel associated with that connection handle
Collaborator
There was a problem hiding this comment.
No, we just need to remove a single channel. However, considering that a handle is impossible to be a key of channels and le_coc_channels at the same time, we can just
def on_channel_closed(self, channel: ClassicChannel | LeCreditBasedChannel) -> None:
if classic_connection_channels := self.channels.get(channel.connection.handle):
classic_connection_channels.pop(channel.source_cid, None)
elif le_connection_channels := self.le_coc_channels.get(channel.connection.handle):
le_connection_channels.pop(channel.destination_cid, None)| connection_channels = self.channels.get(channel.connection.handle) | ||
| if connection_channels: | ||
| if channel.source_cid in connection_channels: | ||
| if connection_channels.get(channel.source_cid) is channel: |
Collaborator
There was a problem hiding this comment.
Suggested change
| if connection_channels.get(channel.source_cid) is channel: | |
| connection_channels.pop(channel.source_cid, None) |
| self._change_state(self.State.DISCONNECTED) | ||
| self.manager.on_channel_closed(self) | ||
| if was_disconnecting and self.disconnection_result: | ||
| self.disconnection_result.set_result(None) |
Collaborator
There was a problem hiding this comment.
I think we can just set connection_result and disconnection_result under any state?
| was_disconnecting = self.state == self.State.DISCONNECTING | ||
| self._change_state(self.State.DISCONNECTED) | ||
| self.manager.on_channel_closed(self) | ||
| if was_disconnecting and self.disconnection_result: |
Resolve a teardown hang in LeCreditBasedChannel. When a disconnection collision occurs (both DUT and peer call disconnect simultaneously) or the channel is aborted during disconnection, the connection state transitions to DISCONNECTED before the peer's response arrives (or is ignored). In these cases, the `disconnection_result` future remained unresolved, causing any awaiting teardown task to hang. This patch ensures that calling abort() or receiving a disconnection request while in the DISCONNECTING state correctly resolves `disconnection_result` and cleans up the channel. Verification: Verified with a new unit test `test_abort_while_disconnecting` added to `tests/l2cap_test.py` that stubs a non-responsive peer and calls abort() during the DISCONNECTING state transition, confirming it completes immediately.
Also includes the test_disconnection_collision unit test.
5464d43 to
4568748
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Resolve a teardown hang in LeCreditBasedChannel. When a disconnection collision occurs (both DUT and peer call disconnect simultaneously) or the channel is aborted during disconnection, the connection state transitions to DISCONNECTED before the peer's response arrives (or is ignored). In these cases, the
disconnection_resultfuture remained unresolved, causing any awaiting teardown task to hang.This patch ensures that calling abort() or receiving a disconnection request while in the DISCONNECTING state correctly resolves
disconnection_resultand cleans up the channel.Verification:
Verified with a new unit test
test_abort_while_disconnectingadded totests/l2cap_test.pythat stubs a non-responsive peer and calls abort() during the DISCONNECTING state transition, confirming it completes immediately.