Repository navigation
Refresh the live runner O2R reader after re-registration - #96
Conversation
There was a problem hiding this comment.
🟡 Changes recommended
Shutdown does not await retired readers, so it can return with cleanup tasks and HTTP sessions still alive.
1 open issue
What changed in this PR
Refreshes the live runner’s reservation-event reader after re-registration so it follows the returned O2R channel.
Changes:
- Reuses healthy readers when normalized URLs match; otherwise starts a replacement.
- Exposes subscriber state and tracks retired reader tasks.
- Adds regression coverage for channel changes and reader health.
| File | Description |
|---|---|
| tests/test_live_runner.py | Tests reader reuse, replacement, and reservation delivery. |
| tests/test_channel_reader.py | Checks subscriber availability during callbacks. |
| src/livepeer_gateway/live_runner.py | Implements reader refresh and retirement tracking. |
| src/livepeer_gateway/channel_reader.py | Retains the active subscriber for health checks. |
Review effort: Balanced
| self._retired_o2r_tasks.add(old_task) | ||
| old_task.add_done_callback(self._retired_o2r_tasks.discard) |
There was a problem hiding this comment.
I reproduced this window. Registration close() can return with a retired reader’s HTTP session still open. Cleanup completed while the event loop stayed up, and cancelling the retired task during teardown interrupted cleanup.
I also verified that a retired application callback can call registration.close() from its own task. Draining all retired tasks there would make that callback wait on itself. A safe drain needs explicit rules for reentrancy, caller cancellation, and how long shutdown should wait. For this PR, I’m keeping retirement asynchronous and the implementation at 14 added lines. A guaranteed drain is a separate shutdown change.

Summary
When heartbeat authorization fails and a live runner registers again, read reservation events from the returned O2R channel. Reuse a healthy reader when the effective URL matches. A replacement can start while the previous reader finishes cleanup.
Alternative to #95.
Validation
mainand passes with this patch.