Prevents race conditions when multiple connection attempts are made
to the same device simultaneously by:
- Adding connectingDevices Set to track in-progress connections
- Checking for concurrent connections before starting new attempt
- Returning early if device is already connected
- Using finally block to ensure cleanup of connecting state
- Clearing connectingDevices set on cleanup
Includes comprehensive test suite for concurrent connection scenarios
including edge cases like rapid connect/disconnect cycles and cleanup
during connection attempts.
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>