Repository navigation
fix(jellycompat): stop binding NUL advisory lock keys - #616
Closed
cursor[bot] wants to merge 1 commit into
Closed
cursor[bot] wants to merge 1 commit into
cursor[bot] wants to merge 1 commit into
Conversation
#529 stripped NUL from durable playback-session JSON, but replaceUnstartedNegotiation still joined token/device/item with U+0000 and bound that string as PostgreSQL text. Postgres rejects NUL in text (SQLSTATE 22021), so every negotiated compat session with a DeviceId failed to persist and stayed cache-only. Join the lock key with chr(31) inside PostgreSQL, matching the marker contribution lock, so the bind parameters stay valid text. Co-authored-by: Quick <[email protected]>
1 of 2 tasks
5 tasks done
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Part of #599
#529 stripped NUL code points from durable playback-session JSON so PostgreSQL would accept the row. That was not enough:
replaceUnstartedNegotiationstill joinedCompatToken,ClientDeviceID, andRouteItemIDwith U+0000 in Go and bound the result as a singletextargument topg_advisory_xact_lock(hashtextextended($1, 0)).PostgreSQL rejects NUL in text (
SQLSTATE 22021). The transaction aborts before the upsert,PutNegotiatedmarks the session unpersisted, and the negotiated PlaySessionId mapping stays cache-only. The first revalidation after a restart or another process then drops playback.This fires for essentially every real Jellyfin-compat client:
HandlePlaybackInfopopulates all three fields whenever the client sends aDeviceId.#599 already captured the failure against a live database:
Approach
Join the lock key inside PostgreSQL with
chr(31), passing the three fields as separate text parameters — the same patterninternal/markers/contribution_repo.goalready uses. Bind parameters never contain the delimiter, so the advisory lock can succeed and the negotiated session is written durably.The in-process mutation lock still uses a NUL-joined Go string; that never leaves the process and is unchanged.
Testing
This environment has no Postgres (
SILO_TEST_DATABASE_URLunset), so the existing DB-backed replacement test skipped. Package tests including the new SQL-shape pin:Also ran
gofmton the touched files,go vet ./internal/jellycompat/, andmake verify-local-paths.When
SILO_TEST_DATABASE_URLis set,TestDurableCompatPlaybackStorePutNegotiatedReplacesAcrossInstancesis the behavioral regression for this failure.AI Disclosure
chr(31)concatenation can theoretically collide if a client-controlled DeviceId contains U+001F; that is the same tradeoff already accepted for marker contribution locks, and DeviceId values are not expected to contain unit separators. I left the in-memory NUL join alone because Go strings may contain NUL. I did not broaden this PR to the other [bug] CI runs no PostgreSQL, so 171 DB-backed tests silently skip — 7 are broken on main and 2 packages are flaky #599 items (CI Postgres, skipped DB tests).Checklist
gofmt,go vet ./internal/jellycompat/,go test ./internal/jellycompat/, andmake verify-local-paths. Fullmake lint/ web lint were not required (no frontend or whole-tree Go style changes).