Skip to content

Commit

Permalink
fix server crash when hub disconnects unexpectedly during program run
Browse files Browse the repository at this point in the history
closes #160
  • Loading branch information
Novakasa committed Jan 3, 2024
1 parent a4a3523 commit 2994147
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

### Fixed

- Fix invalid ble-server state when hub disconnects during program running (e.g. when battery is removed) (https://github.com/Novakasa/brickrail/issues/160).
- Fix pybricks error with motors with rotation encoders in pybricks 3.3-stable (https://github.com/Novakasa/brickrail/issues/174).
- Don't allow adding train to occupied block. This previously created invalid state.
- Fixed Switches and Crossing motors invalidated port when renaming a hub (https://github.com/Novakasa/brickrail/issues/163)
Expand Down
12 changes: 9 additions & 3 deletions ble-server/ble_hub.py
Original file line number Diff line number Diff line change
Expand Up @@ -325,9 +325,15 @@ async def run(self, program=None, wait=False, skip_download=False):
program = str(Path(__file__).parent / "hub_programs" / f"{program}.py")

async def run_coroutine():
await self.hub._wait_for_user_program_stop()
self.program_stopped.set()
self.to_out_queue("program_stopped", None)
try:
await self.hub._wait_for_user_program_stop()
except Exception as err:
self.to_out_queue("program_error", repr(err))
finally:
self.program_stopped.set()
self.to_out_queue("program_stopped", None)
if not self.hub.client.is_connected:
self.to_out_queue("disconnected", None)

async def output_loop():
while True:
Expand Down

0 comments on commit 2994147

Please sign in to comment.