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 <kawasaki@juno.dti.ne.jp>
This commit is contained in:
Shin'ichiro Kawasaki
2021-05-02 17:52:42 +09:00
parent e34ec61f3b
commit c206f7a5c5

View File

@@ -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")