onPlaybackFinished emits its state outside the lock, so a stale 'stopped' can overtake a live 'playing' #123
Closed
opened 2026-08-19 12:37:54 +00:00 by yonlu
·
1 comment
No Branch/Tag Specified
main
fix/146-stub-etxtbsy
fix/175-wizard-follows-the-library
fix/231-setter-rollback
fix/197-duplicate-column-label
docs/225-fixtures-wav-tags
docs/220-skill-check-scope
test/217-fixture-names-in-queue-selection
fix/216-riff-parse-allocation
fix/170-queue-header-action-names
fix/210-nav-sheet-scroll-affordance
docs/50-readme-landing-page
feat/65-art-prefetch-ahead
feat/71-more-as-a-bottom-sheet
feat/54-native-touch-feel
feat/67-entity-links-into-menus
test/196-visual-tier-gates
fix/138-ui-test-storage-leak
fix/104-wav-tags-read
fix/207-sheet-scroll-affordance
fix/204-ui-visual-update-filter
pi-agent-backlog-automation
63-touch-model-phase-2
63-android-touch-model
186-touch-targets-settings
186-touch-targets-page-header
187-seek-bar-hit-area
189-190-explore-correctness
135-android-underrun-instrumentation
51-android-small-screens
fix/171-phone-queue-scrim
fix/137-touch-only-affordances
fix/154-nested-css-check
feat/58-mini-player-progress-line
fix/66-album-page-scrolls-as-one
60-context-menu-action-sheet
64-android-system-volume
59-slim-the-mini-player
55-queue-as-a-screen
feat/57-drop-the-android-top-bar
feat/62-jobs-as-a-notification
fix/53-seek-bar-never-moves
fix/159-android-task-app-id
fix/52-android-activity-recreation-restarts-the-process
fix/150-expand-button-under-the-art
feat/42-inline-volume-and-centred-transport
fix/156-queue-selection-fixture-order
fix/151-fuse-the-scroll-guard-and-the-write
fix/43-queue-panel-selection
fix/143-top-bar-fits-its-window
feat/27-jobs-into-settings
feat/25-configurable-sidebar-tabs
feat/6-global-back-forward
fix/72-active-view-broadcast
fix/69-page-header-action-overflow
fix/quick-wins-batch
fix/118-in-library-clear
fix/61-mini-player-plain-text
fix/68-hover-affordances-pointer
fix/119-dev-headless-port
fix/130-issue-claim-user
fix/131-codegen-check-scope
feat/28-autotag-match-on-album
feat/17-demote-version-selector
feat/38-ownership-visibility
ci/115-manual-release
feat/34-icon-language
feat/7-full-tracklist-toggle
fix/16-tagwriter-totals
fix/unclaim-ca-certs
fix/unclaim-shell
ci/unclaim-on-close
docs/closing-keyword
docs/retire-stale-planning-docs
docs/issue-driven-workflow
integration/small-fixes
fix/small-issue-batch
fix/queue-toggle-state
fix/drag-count-badge
fix/album-card-year
fix/album-tracklist-heading
fix/seek-bar-clock-width
fix/explore-art-scanner-requests
chore/workflow-guardrails
v0.7.0
v0.6.0
v0.5.0
v0.4.0
v0.3.1
v0.3.0
v0.2.3
v0.2.2
v0.2.1
v0.2.0
v0.1.0
v0.0.1
v0.0.0
Labels
Clear labels
Area/Design
Area/Downloads
Area/Explore
Area/Library-UI
Area/Metadata
Area/Packaging
Area/Player
Area/Queue
Area/Settings
Area/Shell-Nav
Compat/Breaking
Kind/Bug
Kind/Documentation
Kind/Enhancement
Kind/Feature
Kind/Security
Kind/Testing
Platform/Android
Platform/Desktop
Breaking change that won't be backward compatible
Something is not working
Documentation changes
Improve existing functionality
New functionality
This is security issue
Issue or pull request related to testing
Priority
Critical
1
The priority is critical
Priority
High
2
The priority is high
Priority
Medium
3
The priority is medium
Priority
Low
4
The priority is low
Reviewed
Confirmed
1
Issue has been confirmed
Reviewed
Duplicate
2
This issue or pull request already exists
Reviewed
Invalid
3
Invalid issue
Reviewed
Won't Fix
3
This issue won't be fixed
Status
Blocked
1
Something is blocking this issue or pull request
Status
Need More Info
2
Feedback is required to reproduce issue or to continue work
Status
Abandoned
3
Somebody has started to work on this but abandoned work
Status
In Progress
Somebody is actively working on this right now
Milestone
No items
No Milestone
Projects
Clear projects
No projects
Notifications
Due Date
No due date set.
Dependencies
No dependencies set.
Reference: yonlu/yellowjacket#123
Reference in New Issue
Block a user
Blocking a user prevents them from interacting with repositories, such as opening or commenting on pull requests or issues. Learn more about blocking a user.
Findings
onPlaybackFinished(backend/player/player.go:492-531) releasesp.muand then emits the two events that tell the frontend what happened:Every other emit in this file happens under
p.mu(:414,:597,:676,:705,:772). This one does not, and the window is real: a user pressing Play, an MPRISOnPlay, or the queue's own auto-advance can takep.muin that gap, drive the player toPlayingand emitPlaybackStateChanged(playing)first. The stalestoppedthen lands last and the frontend'sisPlayingis wrong — inverted against what the player is actually doing, until the next transition.player-storekeys entirely off the last event received; there is no sequence number on this event the way there is onPositionInfo.Two smaller things in the same function, both consequences of the same "the callback does not know which chain it came from" gap:
go p.onPlaybackFinished()(:481) and then has to queue forp.mu. If it queues behind a slowloadFileLocked(a decode plus a DB read), it wakes up holding the mutex for a player that has since loaded and started a different track — and callsp.rewindLocked()andp.emitPositionLocked()against it, then hands a stale finish to the queue's auto-advance. A generation counter (the existingtrackChangeIDwould do) captured when the chain is registered and compared here is the fix.emitPositionLockedis called at:504while the state has already been set toStopped, which is correct, but the ordering of the three emits (position, finished, state) is only meaningful if they cannot be interleaved — which is the same fix.Direction
Emit both events while still holding
p.mu, as every other path does, and capture the chain'strackChangeIDin thebeep.Callbackclosure so a stale callback returns without touching anything.backend/player/emit_test.goalready has the recorder pattern for asserting the payload order.Working this as part of a batch off
fix/player-playing-state(#122, #123, #124, #125, #126) — all five are inbackend/playerandbackend/queue, and #124 and #125 are the two halves of the same fallback expression, so splitting them across branches would mean three passes over the same twenty lines.Approach:
done = trueon everyreadAheadexit; bound the underrun fill and return0, falsepast it; give the finished path a way to tell "drained" from "failed" soPlaybackFailedis emitted instead of a silent auto-advance.p.mu, and capture the chain'strackChangeIDin thebeep.Callbackclosure so a stale callback returns without touching the player.p.formatinloadFileLocked, resetp.trackLengthMsthere, take the replay path's rate fromp.format.currentIndexthe wayloadCurrentTrackalready does.Verified with
make test(all three build configurations) plus new unit tests per exit path; the audible half of #124 needs a 48 kHz fixture.