ble-reticulum/tests
torlando-tech 558d89de9c fix(ble): Add BlueZ state cleanup to prevent persistent "Operation already in progress" errors
Implements comprehensive BlueZ device state cleanup after connection failures
to prevent persistent "Operation already in progress" errors. This addresses
the issue where BlueZ maintains stale connection state after timeouts or
failures, preventing successful reconnection even after blacklist periods expire.

BlueZ State Cleanup Implementation:
- **Explicit client disconnect**: Call client.disconnect() in timeout and failure
  exception handlers to release BlueZ resources
- **D-Bus device removal**: New _remove_bluez_device() method removes stale device
  objects via BlueZ RemoveDevice() API
- **Post-blacklist cleanup**: Trigger BlueZ cleanup when peer is blacklisted after
  reaching max_connection_failures (7 failures)

Impact:
- Enables successful reconnection after temporary connection failures
- Fixes persistent errors across blacklist periods
- Prevents BlueZ from maintaining corrupted connection state
- Particularly important for Android devices with MAC address rotation

Implementation Details:
- linux_bluetooth_driver.py:786-830: New _remove_bluez_device() method
- linux_bluetooth_driver.py:1029-1044: Timeout cleanup (disconnect + removal)
- linux_bluetooth_driver.py:1051-1066: Failure cleanup (disconnect + removal)
- BLEInterface.py:1270-1285: Post-blacklist cleanup hook
- tests/test_bluez_state_cleanup.py: 10 new tests (all passing)

Documentation Updates:
- BLE_PROTOCOL_v2.2.md: New troubleshooting section for persistent InProgress errors
- CLAUDE.md: Added to recent fixes list
- CHANGELOG.md: Comprehensive fix description

Related Issues:
- Addresses "Operation already in progress" errors persisting after connection timeouts
- Fixes reconnection failures after peer blacklisting
- Prevents BlueZ state machine corruption from abandoned BleakClient instances

Testing:
- All 10 new unit tests pass
- Cleanup methods properly handle missing devices and D-Bus unavailability
- Integration testing on Raspberry Pi pending

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-10 00:51:27 -05:00
..
conftest.py Initial commit: BLE Reticulum interface 2025-10-26 19:14:14 -04:00
mock_ble_driver.py Refactor BLEInterface to driver-based architecture 2025-11-03 23:15:22 -05:00
test_ble_peer_interface.py Initial commit: BLE Reticulum interface 2025-10-26 19:14:14 -04:00
test_bleak_threading_hang.py Initial commit: BLE Reticulum interface 2025-10-26 19:14:14 -04:00
test_bleak_with_exec_loading.py Initial commit: BLE Reticulum interface 2025-10-26 19:14:14 -04:00
test_bluez_state_cleanup.py fix(ble): Add BlueZ state cleanup to prevent persistent "Operation already in progress" errors 2025-11-10 00:51:27 -05:00
test_config_directory.py fix: support custom config directories via RNS.Reticulum.configdir 2025-10-28 19:09:48 -04:00
test_error_recovery.py Initial commit: BLE Reticulum interface 2025-10-26 19:14:14 -04:00
test_fragmentation.py Initial commit: BLE Reticulum interface 2025-10-26 19:14:14 -04:00
test_gatt_server.py Initial commit: BLE Reticulum interface 2025-10-26 19:14:14 -04:00
test_installer.sh refactor: make libffi-dev conditional for armhf (32-bit ARM) only 2025-10-29 11:02:51 -04:00
test_integration.py test: Add comprehensive v2.2 protocol test suites 2025-11-07 23:00:30 -05:00
test_multi_device_simulation.py Initial commit: BLE Reticulum interface 2025-10-26 19:14:14 -04:00
test_prioritization.py test: Update integration tests for driver abstraction refactor 2025-11-07 22:48:38 -05:00
test_v2_2_identity_handshake.py test: Add comprehensive v2.2 protocol test suites 2025-11-07 23:00:30 -05:00
test_v2_2_mac_sorting.py test: Add comprehensive v2.2 protocol test suites 2025-11-07 23:00:30 -05:00
test_v2_2_race_conditions.py test: Add comprehensive v2.2 protocol test suites 2025-11-07 23:00:30 -05:00