From c206f7a5c5567ea5c44bd011e6e4479e49765429 Mon Sep 17 00:00:00 2001 From: Shin'ichiro Kawasaki Date: Sun, 2 May 2021 17:52:42 +0900 Subject: [PATCH] BLESession: Close session on Exception When an exception is thrown during a session, still the session no longer works, but still keeps connection. With this status, following device scan can not find the device. This symptom was observed when micro:bit with scratch-microbit.hex is connected to "micro:bit MORE" and BTLEException is thrown. Another symptom observed is the Scratch web page closed and websocket connection slows ConnectionClosedOK exception. To avoid the device scan failure, close the session when an exception is caught. Also improve error message for the exception. Signed-off-by: Shin'ichiro Kawasaki --- pyscrlink/scratch_link.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/pyscrlink/scratch_link.py b/pyscrlink/scratch_link.py index 678458d..b019dfb 100755 --- a/pyscrlink/scratch_link.py +++ b/pyscrlink/scratch_link.py @@ -669,7 +669,8 @@ async def ws_handler(websocket, path): await session.handle() except Exception as e: logger.error(f"Failure in session for web socket path: {path}") - logger.error(e) + logger.error(f"{type(e).__name__}: {e}") + session.close() def stack_trace(): print("in stack_trace")