v0.1.36: Improved Classic Bluetooth connection with cache cleaning on ENOMEM errors\n\n- Added automatic Bluetooth cache clearing when [Errno 12] Out of memory occurs\n- Continue trying other channels instead of immediately falling back to BLE\n- Improved error handling for Classic Bluetooth connections\n- Updated config.yaml with host_dbus and host_network settings for better compatibility\n\nGenerated by Mistral Vibe.\nCo-Authored-By: Mistral Vibe <vibe@mistral.ai>
This commit is contained in:
@@ -426,15 +426,29 @@ async def connect(
|
||||
except (PrinterError, PrinterTimeout) as exc:
|
||||
# On Linux, a stale BlueZ device state can cause RFCOMM connect()
|
||||
# to fail with [Errno 12] Out of memory. This is a known quirk.
|
||||
# We treat this specific error as a signal to fall back to BLE.
|
||||
# We treat this specific error as a signal to clear cache and retry.
|
||||
if isinstance(exc.__cause__, OSError) and exc.__cause__.errno == errno.ENOMEM:
|
||||
print(
|
||||
"Classic Bluetooth connection failed with [Errno 12] Out of memory. "
|
||||
"Falling back to BLE connection."
|
||||
f"Classic Bluetooth connection failed with [Errno 12] Out of memory on channel {ch}. "
|
||||
"Clearing Bluetooth cache and retrying..."
|
||||
)
|
||||
classic = False # Modify flag to trigger BLE path below
|
||||
last_exc = exc
|
||||
break
|
||||
try:
|
||||
# Clear Bluetooth cache
|
||||
remove_cmd = f'echo -e "remove {address}\nquit" | bluetoothctl'
|
||||
proc = await asyncio.create_subprocess_shell(
|
||||
remove_cmd,
|
||||
stdout=asyncio.subprocess.DEVNULL,
|
||||
stderr=asyncio.subprocess.DEVNULL,
|
||||
)
|
||||
await asyncio.wait_for(proc.communicate(), timeout=10.0)
|
||||
print(f" Bluetooth cache cleared for {address}")
|
||||
except Exception as remove_exc:
|
||||
print(f" Failed to clear Bluetooth cache: {remove_exc}")
|
||||
|
||||
# Continue to next channel instead of breaking
|
||||
continue
|
||||
|
||||
# For other errors, continue to next channel
|
||||
last_exc = exc
|
||||
|
||||
# If the 'classic' flag is still true, it means the loop completed without
|
||||
|
||||
Reference in New Issue
Block a user