Skip to content

Commit fc9c85b

Browse files
fix: prevent auto-next double-fire and unblock end-of-queue stop
Two bugs found in auto-next state management: Bug A - Double-fire: check_auto_next() could fire twice for the same track end because state.update(TRANSITIONING) is async and hasn't propagated by the next polling cycle. The _auto_next_in_flight flag was already set synchronously but check_auto_next never checked it. Fix: add _auto_next_in_flight guard at the top of check_auto_next(). Bug B - End-of-queue stop blocked: when auto-next fires for the last track in queue, next() detects end-of-queue and calls stop(), but stop() was blocked by the _auto_next_in_flight guard (which can't distinguish stale Plex stops from legitimate internal stops). Fix: clear _auto_next_in_flight before calling stop() in next()'s end-of-queue branches (offset<0 and offset>=total_count).
1 parent 586e48f commit fc9c85b

1 file changed

Lines changed: 4 additions & 0 deletions

File tree

plex/adapters.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -689,6 +689,8 @@ def check_auto_next(self, changed: DotMap):
689689
return False
690690
if self._suppress_auto_next:
691691
return False
692+
if self._auto_next_in_flight:
693+
return False
692694
if self._active_operation_id:
693695
return False
694696
if self.queue is None:
@@ -1072,10 +1074,12 @@ async def next(self, revert=False):
10721074

10731075
if current_offset < 0:
10741076
logger.debug("%s next guard stop: offset<0 current=%s start=%s", self.dlna.name, current_offset, start_offset)
1077+
self._auto_next_in_flight = False
10751078
await self.stop()
10761079
return
10771080
if not math.isinf(total_count) and current_offset >= total_count:
10781081
logger.debug("%s next guard stop: offset>=total current=%s total=%s", self.dlna.name, current_offset, total_count)
1082+
self._auto_next_in_flight = False
10791083
await self.stop()
10801084
return
10811085
self.state.update(state="TRANSITIONING")

0 commit comments

Comments
 (0)