From 661f86530826d5056e59e06399848c415afe133b Mon Sep 17 00:00:00 2001 From: Sander Date: Sat, 7 Nov 2026 10:55:44 +0100 Subject: [PATCH 1/4] fix(shim): close state-machine gaps in reads, transactions and retries - Eager (non-streaming) reads report execution errors instead of an empty result, like the streaming path. - ROLLBACK on a session lost mid-transaction clears the tracked transaction (it was refused forever); ROLLBACK passes the step-entry session check. Connection teardown forgets transaction state so a connection allocated at the same address cannot inherit it. - The per-thread connection-error flag is cleared at the end of every step instead of leaking into the next failing statement. - The description cache leaves its DDL window when the transaction is really idle (autocommit DDL, not inner RELEASE). - A read-ahead stream stepped from another connection keeps its rows instead of being requeried from row 0. - publish-manual-docker moves :latest only for the latest release. Runtime E2E: new eager_query_errors case; reconnect now rolls back and starts a new transaction after a lost session. Co-Authored-By: Claude Opus 5.5 --- .github/workflows/publish-manual-docker.yml | 13 ++++++- CHANGELOG.md | 8 ++++ rust/plex-pg-core/src/bin/runtime_e2e.rs | 21 +++++++++- .../src/db_interpose_exec/pg_path.rs | 9 +++++ rust/plex-pg-core/src/db_interpose_step.rs | 14 +++++++ .../src/db_interpose_step/retry.rs | 3 ++ .../src/db_interpose_step_read_utils.rs | 16 ++++++++ .../first_execute.rs | 14 +++++++ .../first_execute/eager_fetch.rs | 37 +++++++++++++----- .../first_execute/streaming_fetch.rs | 13 ------- .../reexecution.rs | 4 +- .../write_exec.rs | 1 + .../src/pg_client/connection_lifecycle.rs | 4 ++ .../plex-pg-core/src/pg_client/transaction.rs | 38 ++++++++++++++++++- 14 files changed, 167 insertions(+), 28 deletions(-) diff --git a/.github/workflows/publish-manual-docker.yml b/.github/workflows/publish-manual-docker.yml index 16db384e..8b31483a 100644 --- a/.github/workflows/publish-manual-docker.yml +++ b/.github/workflows/publish-manual-docker.yml @@ -70,6 +70,7 @@ jobs: password: ${{ github.token }} - name: Publish version and latest tags env: + GH_TOKEN: ${{ github.token }} TAG: ${{ inputs.tag }} LINUXSERVER_AMD64: ${{ steps.source.outputs.linuxserver_amd64 }} LINUXSERVER_ARM64: ${{ steps.source.outputs.linuxserver_arm64 }} @@ -77,6 +78,10 @@ jobs: PLEXINC_ARM64: ${{ steps.source.outputs.plexinc_arm64 }} run: | set -eu + # :latest follows the repository's latest GitHub release, so a + # manual publication of an older or newer-but-unreleased tag never + # replaces the image of the current (possibly certified) release. + latest_release=$(gh release view --repo "$GITHUB_REPOSITORY" --json tagName --jq .tagName) publish() { local repository=$1 amd64=$2 arm64=$3 if docker buildx imagetools inspect "$repository:$TAG" >/dev/null 2>&1; then @@ -86,8 +91,12 @@ jobs: docker buildx imagetools create --tag "$repository:$TAG" "$amd64" "$arm64" digest=$(docker buildx imagetools inspect "$repository:$TAG" | awk '/^Digest:/ {print $2; exit}') [[ "$digest" =~ ^sha256:[0-9a-f]{64}$ ]] - docker buildx imagetools create --tag "$repository:latest" "$repository@$digest" - echo "$repository:$TAG -> $digest" >> "$GITHUB_STEP_SUMMARY" + if [[ "$latest_release" == "$TAG" ]]; then + docker buildx imagetools create --tag "$repository:latest" "$repository@$digest" + echo "$repository:$TAG and :latest -> $digest" >> "$GITHUB_STEP_SUMMARY" + else + echo "$repository:$TAG -> $digest (:latest left on $latest_release)" >> "$GITHUB_STEP_SUMMARY" + fi } publish ghcr.io/cgnl/plex-postgresql-linuxserver "$LINUXSERVER_AMD64" "$LINUXSERVER_ARM64" publish ghcr.io/cgnl/plex-postgresql-plexinc "$PLEXINC_AMD64" "$PLEXINC_ARM64" diff --git a/CHANGELOG.md b/CHANGELOG.md index 13914a8d..bdc0c4dd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,14 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +### Fixed +- A read that fails while PostgreSQL executes it now reports the error. Reads that do not stream (for example `LIMIT 1` queries) returned an empty result instead, with only a log line. +- `ROLLBACK` after the PostgreSQL session was lost mid-transaction succeeds and clears the transaction; the handle could not start a new transaction until it was closed. Closed or destroyed connections no longer leave transaction state behind for a later connection at the same address. +- A connection error noted during one step no longer makes the next failing statement on the same thread retry as if its connection had failed. +- The result-description cache resumes after DDL that ran outside a transaction, and an inner `RELEASE SAVEPOINT` no longer ends the DDL window early. +- A statement whose stream was read ahead is no longer re-run from the first row when it is stepped from another connection. +- Manual image publication only moves `:latest` when it publishes the repository's latest release. + ## [1.3.26] - 2026-11-06 ### Fixed diff --git a/rust/plex-pg-core/src/bin/runtime_e2e.rs b/rust/plex-pg-core/src/bin/runtime_e2e.rs index 8f889faa..0511d141 100644 --- a/rust/plex-pg-core/src/bin/runtime_e2e.rs +++ b/rust/plex-pg-core/src/bin/runtime_e2e.rs @@ -399,7 +399,7 @@ fn run() -> Result<()> { &'static str, fn(&Api, &Db<'_>, &Db<'_>, &mut Client) -> Result<()>, ); - let cases: [Case; 21] = [ + let cases: [Case; 22] = [ ( "native_uuid_binding_ownership", |api, first, _, observer| { @@ -1153,6 +1153,19 @@ fn run() -> Result<()> { ) }, ), + ( + // `LIMIT 1` reads take the eager (non-streaming) path; a query that + // fails while executing must report an error, not an empty result. + "eager_query_errors", + |api, first, _, _| { + let stmt = first.prepare("SELECT CAST(1 AS INTEGER) / CAST(abs(random()) * 0 AS INTEGER) AS boom LIMIT 1")?; + let code = unsafe { (api.step)(stmt.handle) }; + require(code != ROW && code != DONE, "failed eager query reported success")?; + require(!api.error(first.handle).is_empty(), "failed eager query lacks diagnostics")?; + require(unsafe { (api.step)(stmt.handle) } != ROW, "failed eager query produced rows")?; + Ok(()) + }, + ), ( // Plex 1.43.5 migration 202609141200 records a preference this way; // a failure aborted the migration on a fresh database. @@ -1274,6 +1287,12 @@ fn run() -> Result<()> { .is_err(), "interrupted transaction silently resumed in autocommit", )?; + // The server discarded the transaction with the session; ROLLBACK + // must clear it so the handle can start new transactions. + first.exec("ROLLBACK")?; + first.exec("BEGIN")?; + first.exec("INSERT INTO runtime_items (unique_value) VALUES (603)")?; + first.exec("COMMIT")?; require( observer.query_one("SELECT COUNT(*) FROM runtime_e2e.runtime_items WHERE unique_value IN (601,602)", &[]).map_err(|error| error.to_string())?.get::<_, i64>(0) == 0, "interrupted transaction persisted partial writes", diff --git a/rust/plex-pg-core/src/db_interpose_exec/pg_path.rs b/rust/plex-pg-core/src/db_interpose_exec/pg_path.rs index a1685306..1be15aab 100644 --- a/rust/plex-pg-core/src/db_interpose_exec/pg_path.rs +++ b/rust/plex-pg-core/src/db_interpose_exec/pg_path.rs @@ -261,6 +261,7 @@ pub(crate) fn exec_via_postgres( let status = crate::libpq_helpers::rust_pq_result_status(res); if status == PGRES_COMMAND_OK || status == PGRES_TUPLES_OK { + note_autocommit_end(pg.conn); clear_pg_last_error(pg_conn); let cmd_tuples = crate::libpq_helpers::rust_pq_cmd_tuples(res); let tuples_ptr = if cmd_tuples.is_null() { @@ -365,3 +366,11 @@ pub(crate) fn exec_via_postgres( SQLITE_OK } } + +/// DDL outside a transaction is committed as soon as it ran; let the +/// description cache resume (otherwise only a later transaction end would). +pub(crate) fn note_autocommit_end(pq: *mut crate::libpq_helpers::PGconn) { + if crate::libpq_helpers::rust_pq_transaction_status(pq) == 0 { + crate::descriptor_cache::transaction_ended(); + } +} diff --git a/rust/plex-pg-core/src/db_interpose_step.rs b/rust/plex-pg-core/src/db_interpose_step.rs index 19a0f6da..c2db3129 100644 --- a/rust/plex-pg-core/src/db_interpose_step.rs +++ b/rust/plex-pg-core/src/db_interpose_step.rs @@ -199,6 +199,7 @@ unsafe fn my_sqlite3_step_impl(p_stmt: *mut sqlite3_stmt) -> c_int { let original_sql = call_sqlite3_sql(p_stmt); let sql = crate::db_interpose_helpers::cstr_to_str_or_empty(original_sql); if !crate::pg_config::is_sqlite_passthrough_str(sql) + && !statement_is_rollback(p_stmt, sql) && !crate::pg_client::transaction::session_ready(handle_conn) { return SQLITE_ERROR; @@ -472,3 +473,16 @@ unsafe fn my_sqlite3_step_impl(p_stmt: *mut sqlite3_stmt) -> c_int { } rc } + +/// ROLLBACK may run on a lost session (it clears the tracked transaction). +/// PostgreSQL statements wrap a placeholder SQLite statement, so the original +/// SQL comes from the shim's statement when there is one. +unsafe fn statement_is_rollback(p_stmt: *mut sqlite3_stmt, sqlite_sql: &str) -> bool { + let pg_stmt = crate::pg_statement::rust_stmt_find(p_stmt as usize) as *mut PgStmt; + let sql = if pg_stmt.is_null() || (*pg_stmt).sql.is_null() { + sqlite_sql + } else { + crate::db_interpose_helpers::cstr_to_str_or_empty((*pg_stmt).sql) + }; + crate::pg_client::transaction::is_rollback_sql(sql) +} diff --git a/rust/plex-pg-core/src/db_interpose_step/retry.rs b/rust/plex-pg-core/src/db_interpose_step/retry.rs index 607c1e3b..5e4ebc6c 100644 --- a/rust/plex-pg-core/src/db_interpose_step/retry.rs +++ b/rust/plex-pg-core/src/db_interpose_step/retry.rs @@ -79,5 +79,8 @@ pub(super) fn maybe_retry_step(p_stmt: *mut sqlite3_stmt, rc: c_int) -> Option c_int { + if crate::libpq_helpers::rust_pq_status(pq) != 0 { + 0 + } else { + -1 + } +} + pub(super) fn first_execute_impl( pg_stmt: *mut PgStmt, exec_conn_io: *mut *mut PgConnection, @@ -113,6 +126,7 @@ pub(super) fn first_execute_impl( exec_conn, &mut stmt_guard, &mut conn_guard, + pg_conn_error_out, ) } } diff --git a/rust/plex-pg-core/src/db_interpose_step_read_utils/first_execute/eager_fetch.rs b/rust/plex-pg-core/src/db_interpose_step_read_utils/first_execute/eager_fetch.rs index 822335ce..f0f45496 100644 --- a/rust/plex-pg-core/src/db_interpose_step_read_utils/first_execute/eager_fetch.rs +++ b/rust/plex-pg-core/src/db_interpose_step_read_utils/first_execute/eager_fetch.rs @@ -6,6 +6,7 @@ pub(super) unsafe fn eager_fetch_result( exec_conn: *mut PgConnection, stmt_guard: &mut Option, conn_guard: &mut PthreadMutexGuard, + pg_conn_error_out: *mut c_int, ) -> c_int { let s = &mut *pg_stmt; let ec = &*exec_conn; @@ -39,18 +40,34 @@ pub(super) unsafe fn eager_fetch_result( *stmt_guard = None; // unlock return STEP_RESULT_ROW; } - } else if !s.result.is_null() { - let err2 = crate::libpq_helpers::rust_pq_error_message(ec.conn); - let ctx = CString::new("EAGER FALLBACK").unwrap(); - let fallback_err = if err2.is_null() { - CString::new("?").unwrap() + } else { + // A failed query is an error, as on the streaming path; it used to + // come back as an empty result with only a log line. + if s.result.is_null() { + crate::db_interpose_exec::pg_path::set_pg_last_error( + s.conn, + "PostgreSQL returned no result", + ); } else { - CString::new(cstr_to_str(err2)).unwrap_or_else(|_| CString::new("?").unwrap()) - }; - log_sql_fallback(s.sql, s.pg_sql, fallback_err.as_ptr(), ctx.as_ptr()); - crate::libpq_helpers::rust_pq_clear(s.result); - s.result = std::ptr::null_mut(); + let err2 = crate::libpq_helpers::rust_pq_error_message(ec.conn); + let ctx = CString::new("EAGER FALLBACK").unwrap(); + let fallback_err = if err2.is_null() { + CString::new("?").unwrap() + } else { + CString::new(cstr_to_str(err2)).unwrap_or_else(|_| CString::new("?").unwrap()) + }; + log_sql_fallback(s.sql, s.pg_sql, fallback_err.as_ptr(), ctx.as_ptr()); + crate::db_interpose_exec::pg_path::record_pg_result_error(s.conn, exec_conn, s.result); + crate::libpq_helpers::rust_pq_clear(s.result); + s.result = std::ptr::null_mut(); + } + s.result_conn = std::ptr::null_mut(); + s.read_done = first_fetch_failure_state(ec.conn); crate::pg_client::rust_pool_check_health(exec_conn as *mut c_void); + *exec_conn_io = exec_conn; + *stmt_guard = None; // unlock + set_pg_conn_error(pg_conn_error_out); + return STEP_RESULT_ERROR; } s.read_done = 1; diff --git a/rust/plex-pg-core/src/db_interpose_step_read_utils/first_execute/streaming_fetch.rs b/rust/plex-pg-core/src/db_interpose_step_read_utils/first_execute/streaming_fetch.rs index 4f6786f3..1d25ffc1 100644 --- a/rust/plex-pg-core/src/db_interpose_step_read_utils/first_execute/streaming_fetch.rs +++ b/rust/plex-pg-core/src/db_interpose_step_read_utils/first_execute/streaming_fetch.rs @@ -117,16 +117,3 @@ pub(super) unsafe fn streaming_fetch_result( set_pg_conn_error(pg_conn_error_out); STEP_RESULT_ERROR } - -/// `read_done` after the first fetch failed. No row has reached the caller, so -/// when the session was lost the statement stays retryable: the step retry -/// re-runs it on the recovered session (a read prepared from the description -/// cache meets a dead session only here, not at prepare). Any other failure is -/// final. -unsafe fn first_fetch_failure_state(pq: *mut crate::libpq_helpers::PGconn) -> c_int { - if crate::libpq_helpers::rust_pq_status(pq) != 0 { - 0 - } else { - -1 - } -} diff --git a/rust/plex-pg-core/src/db_interpose_step_read_utils/reexecution.rs b/rust/plex-pg-core/src/db_interpose_step_read_utils/reexecution.rs index 90779b22..aa1e4f7a 100644 --- a/rust/plex-pg-core/src/db_interpose_step_read_utils/reexecution.rs +++ b/rust/plex-pg-core/src/db_interpose_step_read_utils/reexecution.rs @@ -12,7 +12,9 @@ pub(crate) fn should_clear_cross_thread_result( if stmt.result_conn == exec_conn { return false; } - stmt.streaming_mode != 0 + // A stream that was read ahead no longer needs its connection: its + // remaining rows are local. Requerying it would deliver from row 0 again. + stmt.streaming_mode != 0 && stmt.spill_state == 0 } pub(crate) fn should_use_streaming(stmt: *const PgStmt, disable_streaming_env: bool) -> bool { diff --git a/rust/plex-pg-core/src/db_interpose_step_write_utils/write_exec.rs b/rust/plex-pg-core/src/db_interpose_step_write_utils/write_exec.rs index d81508db..5add63aa 100644 --- a/rust/plex-pg-core/src/db_interpose_step_write_utils/write_exec.rs +++ b/rust/plex-pg-core/src/db_interpose_step_write_utils/write_exec.rs @@ -245,6 +245,7 @@ pub extern "C" fn rust_step_write_execute_and_finalize( } crate::db_interpose_exec::pg_path::copy_pg_outcome(handle_conn, exec_conn); + crate::db_interpose_exec::pg_path::note_autocommit_end(ec.conn); stmt.write_executed = 1; if !res.is_null() { // A statement Plex wrote with RETURNING produces rows, as in diff --git a/rust/plex-pg-core/src/pg_client/connection_lifecycle.rs b/rust/plex-pg-core/src/pg_client/connection_lifecycle.rs index fac6080c..ea66ec14 100644 --- a/rust/plex-pg-core/src/pg_client/connection_lifecycle.rs +++ b/rust/plex-pg-core/src/pg_client/connection_lifecycle.rs @@ -164,6 +164,7 @@ pub(super) fn destroy_pool_connection(conn: *mut c_void) { } pool().forget_live_pool_connection(conn_ptr as *const c_void); rust_stmt_cache_drop(conn_ptr as *mut c_void); + super::transaction::forget_connection(conn_ptr); // SAFETY: conn_ptr is non-null after the check above. let conn = unsafe { &mut *conn_ptr }; if !conn.conn.is_null() { @@ -273,6 +274,9 @@ pub(super) fn close_handle_connection(conn_ptr: *mut PgConnection) { } rust_stmt_cache_clear(conn_ptr as *mut c_void); rust_stmt_cache_drop(conn_ptr as *mut c_void); + // A later connection may be allocated at this address; it must not + // inherit this one's transaction state. + super::transaction::forget_connection(conn_ptr); // SAFETY: conn_ptr is non-null after the check above. let conn = unsafe { &mut *conn_ptr }; let _conn_guard = unsafe { PthreadMutexGuard::lock(&mut conn.mutex as *mut _) }; diff --git a/rust/plex-pg-core/src/pg_client/transaction.rs b/rust/plex-pg-core/src/pg_client/transaction.rs index 3d441056..9cba1ab7 100644 --- a/rust/plex-pg-core/src/pg_client/transaction.rs +++ b/rust/plex-pg-core/src/pg_client/transaction.rs @@ -32,6 +32,29 @@ fn state_for(conn: *mut PgConnection) -> Arc> { .clone() } +/// A transaction is tracked but can no longer be on this session: the session +/// is unusable, was replaced, or is idle. +/// Caller holds the connection mutex. +unsafe fn session_lost_locked(conn: *mut PgConnection) -> bool { + let state = state_for(conn); + let state = state.lock().unwrap_or_else(|poison| poison.into_inner()); + state.active + && ((*conn).conn.is_null() + || rust_pq_status((*conn).conn) != super::session::CONNECTION_OK + || state.session != (*conn).conn as usize + || rust_pq_transaction_status((*conn).conn) == 0) +} + +fn forget_lost_transaction(conn: *mut PgConnection) { + let state = state_for(conn); + *state.lock().unwrap_or_else(|poison| poison.into_inner()) = TransactionState::default(); + crate::descriptor_cache::transaction_ended(); + unsafe { + (*conn).last_error_code = 0; + (*conn).last_error.fill(0); + } +} + pub(crate) fn forget_connection(conn: *mut PgConnection) { states() .lock() @@ -232,6 +255,12 @@ fn tokenize(sql: &str) -> Result, &'static str> { Ok(tokens) } +/// A plain ROLLBACK (not ROLLBACK TO): allowed through the session check so +/// it can clear a transaction whose session was lost. +pub(crate) fn is_rollback_sql(sql: &str) -> bool { + is_transaction_sql(sql) && matches!(parse(sql), Ok(Control::Rollback)) +} + pub(crate) fn is_transaction_sql(sql: &str) -> bool { let sql = crate::pg_config::strip_leading_ws_and_sql_comments(sql); let keyword = sql @@ -379,6 +408,13 @@ pub(crate) fn execute_transaction(conn: *mut PgConnection, sql: &str) -> Option< unsafe fn execute(conn: *mut PgConnection, sql: &str) -> Result { let _guard = PthreadMutexGuard::lock(&mut (*conn).mutex); let control = parse(sql).map_err(|message| set_error(conn, message))?; + if matches!(control, Control::Rollback) && session_lost_locked(conn) { + // The server discarded the transaction with the session, so the + // rollback has already happened; forget it instead of refusing + // forever (nothing else clears a transaction whose session is gone). + forget_lost_transaction(conn); + return Ok(0); + } if (*conn).conn.is_null() || rust_pq_status((*conn).conn) != super::session::CONNECTION_OK { return Err(set_error( conn, @@ -492,7 +528,7 @@ unsafe fn execute(conn: *mut PgConnection, sql: &str) -> Result { } } } - if ends_transaction { + if ends_transaction && rust_pq_transaction_status((*conn).conn) == 0 { crate::descriptor_cache::transaction_ended(); } (*conn).last_error_code = 0; From ed0ac56427bf210d3a98aae0b4a3e869fb3add6c Mon Sep 17 00:00:00 2001 From: Sander Date: Sat, 7 Nov 2026 11:04:56 +0100 Subject: [PATCH 2/4] fix(shim): address review of the state-machine fixes Codex review of the previous commit: - A COMMIT whose session breaks has an unknown outcome; the following ROLLBACK still clears the transaction but reports that instead of claiming success. - The description cache tracks uncommitted DDL per session (the session that executed it) instead of one global flag, so another session's commit or autocommit write cannot end the window and let an old description be cached. - publish-manual-docker runs in the certified publisher's concurrency group and re-reads the latest release right before moving :latest. Co-Authored-By: Claude Opus 5.5 --- .github/workflows/publish-manual-docker.yml | 5 +- CHANGELOG.md | 6 +- .../src/db_interpose_exec/pg_path.rs | 23 +++++-- .../write_exec.rs | 2 +- rust/plex-pg-core/src/descriptor_cache.rs | 64 ++++++++++++++----- .../plex-pg-core/src/pg_client/transaction.rs | 55 ++++++++++++---- 6 files changed, 115 insertions(+), 40 deletions(-) diff --git a/.github/workflows/publish-manual-docker.yml b/.github/workflows/publish-manual-docker.yml index 8b31483a..d8586f2f 100644 --- a/.github/workflows/publish-manual-docker.yml +++ b/.github/workflows/publish-manual-docker.yml @@ -20,8 +20,9 @@ on: permissions: contents: read +# Same group as the certified publisher: both may move :latest. concurrency: - group: manual-release-docker + group: certified-release-publication cancel-in-progress: false jobs: @@ -91,6 +92,8 @@ jobs: docker buildx imagetools create --tag "$repository:$TAG" "$amd64" "$arm64" digest=$(docker buildx imagetools inspect "$repository:$TAG" | awk '/^Digest:/ {print $2; exit}') [[ "$digest" =~ ^sha256:[0-9a-f]{64}$ ]] + # Re-read right before promoting in case a release was published meanwhile. + latest_release=$(gh release view --repo "$GITHUB_REPOSITORY" --json tagName --jq .tagName) if [[ "$latest_release" == "$TAG" ]]; then docker buildx imagetools create --tag "$repository:latest" "$repository@$digest" echo "$repository:$TAG and :latest -> $digest" >> "$GITHUB_STEP_SUMMARY" diff --git a/CHANGELOG.md b/CHANGELOG.md index bdc0c4dd..afa0221d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,11 +10,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Fixed - A read that fails while PostgreSQL executes it now reports the error. Reads that do not stream (for example `LIMIT 1` queries) returned an empty result instead, with only a log line. -- `ROLLBACK` after the PostgreSQL session was lost mid-transaction succeeds and clears the transaction; the handle could not start a new transaction until it was closed. Closed or destroyed connections no longer leave transaction state behind for a later connection at the same address. +- `ROLLBACK` after the PostgreSQL session was lost mid-transaction clears the transaction; the handle could not start a new transaction until it was closed. It succeeds, unless the session broke during `COMMIT`: then it reports that the commit's outcome is unknown. Closed or destroyed connections no longer leave transaction state behind for a later connection at the same address. - A connection error noted during one step no longer makes the next failing statement on the same thread retry as if its connection had failed. -- The result-description cache resumes after DDL that ran outside a transaction, and an inner `RELEASE SAVEPOINT` no longer ends the DDL window early. +- The result-description cache tracks uncommitted DDL per session: it resumes after DDL that ran outside a transaction, and another session's commit or autocommit write (or an inner `RELEASE SAVEPOINT`) no longer ends the window early. - A statement whose stream was read ahead is no longer re-run from the first row when it is stepped from another connection. -- Manual image publication only moves `:latest` when it publishes the repository's latest release. +- Manual image publication only moves `:latest` when it publishes the repository's latest release, checked right before promotion, and runs serialised with the certified publisher. ## [1.3.26] - 2026-11-06 diff --git a/rust/plex-pg-core/src/db_interpose_exec/pg_path.rs b/rust/plex-pg-core/src/db_interpose_exec/pg_path.rs index 1be15aab..6ad6a56a 100644 --- a/rust/plex-pg-core/src/db_interpose_exec/pg_path.rs +++ b/rust/plex-pg-core/src/db_interpose_exec/pg_path.rs @@ -261,7 +261,7 @@ pub(crate) fn exec_via_postgres( let status = crate::libpq_helpers::rust_pq_result_status(res); if status == PGRES_COMMAND_OK || status == PGRES_TUPLES_OK { - note_autocommit_end(pg.conn); + note_write_done(pg_conn, CStr::from_ptr(sql).to_bytes(), true); clear_pg_last_error(pg_conn); let cmd_tuples = crate::libpq_helpers::rust_pq_cmd_tuples(res); let tuples_ptr = if cmd_tuples.is_null() { @@ -367,10 +367,21 @@ pub(crate) fn exec_via_postgres( } } -/// DDL outside a transaction is committed as soon as it ran; let the -/// description cache resume (otherwise only a later transaction end would). -pub(crate) fn note_autocommit_end(pq: *mut crate::libpq_helpers::PGconn) { - if crate::libpq_helpers::rust_pq_transaction_status(pq) == 0 { - crate::descriptor_cache::transaction_ended(); +/// A write succeeded on `conn`. DDL opens a description-cache window that +/// ends once the session is idle; outside a transaction that is right away. +pub(crate) fn note_write_done(conn: *mut crate::ffi_types::PgConnection, sql: &[u8], batch: bool) { + if conn.is_null() { + return; + } + let ddl = if batch { + crate::descriptor_cache::batch_contains_ddl(sql) + } else { + crate::descriptor_cache::starts_with_ddl(sql) + }; + if ddl { + crate::descriptor_cache::ddl_executed(conn as usize); + } + if unsafe { crate::libpq_helpers::rust_pq_transaction_status((*conn).conn) } == 0 { + crate::descriptor_cache::connection_idle(conn as usize); } } diff --git a/rust/plex-pg-core/src/db_interpose_step_write_utils/write_exec.rs b/rust/plex-pg-core/src/db_interpose_step_write_utils/write_exec.rs index 5add63aa..22b01040 100644 --- a/rust/plex-pg-core/src/db_interpose_step_write_utils/write_exec.rs +++ b/rust/plex-pg-core/src/db_interpose_step_write_utils/write_exec.rs @@ -245,7 +245,7 @@ pub extern "C" fn rust_step_write_execute_and_finalize( } crate::db_interpose_exec::pg_path::copy_pg_outcome(handle_conn, exec_conn); - crate::db_interpose_exec::pg_path::note_autocommit_end(ec.conn); + crate::db_interpose_exec::pg_path::note_write_done(exec_conn, cstr_bytes(stmt.sql), false); stmt.write_executed = 1; if !res.is_null() { // A statement Plex wrote with RETURNING produces rows, as in diff --git a/rust/plex-pg-core/src/descriptor_cache.rs b/rust/plex-pg-core/src/descriptor_cache.rs index 040bead5..0c03e010 100644 --- a/rust/plex-pg-core/src/descriptor_cache.rs +++ b/rust/plex-pg-core/src/descriptor_cache.rs @@ -12,10 +12,10 @@ //! - DDL seen anywhere in the shim (prepare, free, `sqlite3_exec`) clears the //! cache and bumps a generation; a description taken before the bump is not //! stored afterwards. -//! - While DDL may be uncommitted, nothing is stored, and the end of the next -//! transaction clears the cache again (another session may have described -//! the old shape before the commit, or this session the new shape before a -//! rollback). +//! - While any session has executed DDL that is not yet committed or rolled +//! back, nothing is stored; when that session is idle again the cache is +//! cleared (another session may have described the old shape before the +//! commit, or this session the new shape before a rollback). //! - Statements that name a temporary table are never cached (temporary //! tables are per session; the cache is per process). //! - An execution whose columns differ from the description replaces it (see @@ -25,7 +25,7 @@ use std::collections::HashMap; use std::ffi::CStr; use std::os::raw::c_int; -use std::sync::atomic::{AtomicBool, AtomicU64, Ordering}; +use std::sync::atomic::{AtomicU64, Ordering}; use std::sync::{LazyLock, Mutex}; use crate::libpq_helpers::{self, PGresult, PG_COPYRES_ATTRS}; @@ -41,6 +41,9 @@ struct Cache { entries: HashMap, Vec<(c_int, usize)>>, len: usize, temporary_tables: Vec>, + /// Sessions (connection addresses) that executed DDL not yet committed + /// or rolled back. Nothing is stored while any exists. + ddl_sessions: Vec, } static CACHE: LazyLock> = LazyLock::new(|| { @@ -48,10 +51,10 @@ static CACHE: LazyLock> = LazyLock::new(|| { entries: HashMap::new(), len: 0, temporary_tables: Vec::new(), + ddl_sessions: Vec::new(), }) }); static GENERATION: AtomicU64 = AtomicU64::new(0); -static DDL_PENDING: AtomicBool = AtomicBool::new(false); fn with_cache(f: impl FnOnce(&mut Cache) -> T) -> T { let mut cache = CACHE.lock().unwrap_or_else(|poison| poison.into_inner()); @@ -90,12 +93,13 @@ pub(crate) fn lookup(sql: &CStr, param_count: c_int) -> *mut PGresult { /// may have changed since `described_at` (a `generation()` value). pub(crate) fn store(sql: &CStr, param_count: c_int, descriptor: *const PGresult, described_at: u64) { let bytes = sql.to_bytes(); - if bytes.len() > MAX_SQL_BYTES || DDL_PENDING.load(Ordering::SeqCst) { + if bytes.len() > MAX_SQL_BYTES { return; } with_cache(|cache| { // Checked under the lock: `clear` bumps the generation under it too. if GENERATION.load(Ordering::SeqCst) != described_at + || !cache.ddl_sessions.is_empty() || cache.temporary_tables.iter().any(|name| contains_word(bytes, name)) { return; @@ -143,10 +147,8 @@ pub(crate) fn clear() { }); } -/// A CREATE/ALTER/DROP is about to run or has run. Stops caching until the -/// end of the next transaction, which clears again. +/// A CREATE/ALTER/DROP is about to run: drop what was cached so far. pub(crate) fn note_ddl(sql: &[u8]) { - DDL_PENDING.store(true, Ordering::SeqCst); let temporary = temporary_table_name(sql); with_cache(|cache| { GENERATION.fetch_add(1, Ordering::SeqCst); @@ -159,11 +161,29 @@ pub(crate) fn note_ddl(sql: &[u8]) { }); } -/// A transaction ended (COMMIT, ROLLBACK, RELEASE, ROLLBACK TO). -pub(crate) fn transaction_ended() { - if DDL_PENDING.swap(false, Ordering::SeqCst) { - clear(); - } +/// DDL ran on `session`. Until that session is idle again (its transaction +/// committed or rolled back), other sessions may still see the old schema +/// and this one the new, so nothing is cached. +pub(crate) fn ddl_executed(session: usize) { + with_cache(|cache| { + GENERATION.fetch_add(1, Ordering::SeqCst); + clear_entries(cache); + if !cache.ddl_sessions.contains(&session) { + cache.ddl_sessions.push(session); + } + }); +} + +/// `session` has no open transaction (or is gone). Ends its DDL window, if +/// any; the schema others see may just have changed, so drop the cache. +pub(crate) fn connection_idle(session: usize) { + with_cache(|cache| { + if let Some(position) = cache.ddl_sessions.iter().position(|&s| s == session) { + cache.ddl_sessions.swap_remove(position); + GENERATION.fetch_add(1, Ordering::SeqCst); + clear_entries(cache); + } + }); } fn skip_space_and_comments(sql: &[u8]) -> &[u8] { @@ -256,6 +276,20 @@ mod tests { assert!(!starts_with_ddl(b"")); } + fn ddl_window_open_for(session: usize) -> bool { + with_cache(|cache| cache.ddl_sessions.contains(&session)) + } + + #[test] + fn ddl_window_is_closed_only_by_its_own_session() { + let (ddl, other) = (0xD01usize, 0xD02usize); + ddl_executed(ddl); + connection_idle(other); + assert!(ddl_window_open_for(ddl), "another session closed the DDL window"); + connection_idle(ddl); + assert!(!ddl_window_open_for(ddl)); + } + #[test] fn exec_batches_with_ddl_are_detected() { assert!(batch_contains_ddl(b"BEGIN; ALTER TABLE t ADD c int; COMMIT")); diff --git a/rust/plex-pg-core/src/pg_client/transaction.rs b/rust/plex-pg-core/src/pg_client/transaction.rs index 9cba1ab7..57b5dfc7 100644 --- a/rust/plex-pg-core/src/pg_client/transaction.rs +++ b/rust/plex-pg-core/src/pg_client/transaction.rs @@ -11,6 +11,9 @@ use crate::libpq_helpers::*; struct TransactionState { active: bool, implicit: bool, + /// The session failed while COMMIT was in flight: the server may or may + /// not have committed. + commit_outcome_unknown: bool, session: usize, next_savepoint: u64, savepoints: Vec<(String, String)>, @@ -45,17 +48,22 @@ unsafe fn session_lost_locked(conn: *mut PgConnection) -> bool { || rust_pq_transaction_status((*conn).conn) == 0) } -fn forget_lost_transaction(conn: *mut PgConnection) { +/// Returns whether a COMMIT was in flight when the session was lost. +fn forget_lost_transaction(conn: *mut PgConnection) -> bool { let state = state_for(conn); - *state.lock().unwrap_or_else(|poison| poison.into_inner()) = TransactionState::default(); - crate::descriptor_cache::transaction_ended(); + let mut state = state.lock().unwrap_or_else(|poison| poison.into_inner()); + let unknown = state.commit_outcome_unknown; + *state = TransactionState::default(); + crate::descriptor_cache::connection_idle(conn as usize); unsafe { (*conn).last_error_code = 0; (*conn).last_error.fill(0); } + unknown } pub(crate) fn forget_connection(conn: *mut PgConnection) { + crate::descriptor_cache::connection_idle(conn as usize); states() .lock() .unwrap_or_else(|poison| poison.into_inner()) @@ -376,6 +384,24 @@ pub(crate) unsafe fn set_error(conn: *mut PgConnection, message: &str) -> c_int 1 } +/// Run COMMIT/ROLLBACK; a COMMIT that fails because the session broke has +/// an unknown outcome, which a later ROLLBACK must report. +unsafe fn commit_or_mark_unknown( + conn: *mut PgConnection, + state: &mut TransactionState, + committing: bool, + sql: &str, +) -> Result<(), c_int> { + let outcome = command(conn, sql); + if outcome.is_err() + && committing + && ((*conn).conn.is_null() || rust_pq_status((*conn).conn) != super::session::CONNECTION_OK) + { + state.commit_outcome_unknown = true; + } + outcome +} + unsafe fn command(conn: *mut PgConnection, sql: &str) -> Result<(), c_int> { let sql = CString::new(sql).map_err(|_| set_error(conn, "Invalid transaction SQL"))?; let result = rust_pq_exec((*conn).conn, sql.as_ptr()); @@ -412,7 +438,14 @@ unsafe fn execute(conn: *mut PgConnection, sql: &str) -> Result { // The server discarded the transaction with the session, so the // rollback has already happened; forget it instead of refusing // forever (nothing else clears a transaction whose session is gone). - forget_lost_transaction(conn); + // Unless a COMMIT was in flight: then it may have committed. + let unknown = forget_lost_transaction(conn); + if unknown { + return Err(set_error( + conn, + "PostgreSQL session was lost during COMMIT; whether it committed is unknown", + )); + } return Ok(0); } if (*conn).conn.is_null() || rust_pq_status((*conn).conn) != super::session::CONNECTION_OK { @@ -471,14 +504,8 @@ unsafe fn execute(conn: *mut PgConnection, sql: &str) -> Result { "Cannot commit an aborted PostgreSQL transaction; rollback required", )); } - command( - conn, - if matches!(control, Control::Commit) { - "COMMIT" - } else { - "ROLLBACK" - }, - )?; + let committing = matches!(control, Control::Commit); + commit_or_mark_unknown(conn, &mut state, committing, if committing { "COMMIT" } else { "ROLLBACK" })?; *state = TransactionState::default(); } Control::Savepoint(name) => { @@ -510,7 +537,7 @@ unsafe fn execute(conn: *mut PgConnection, sql: &str) -> Result { "Cannot release an aborted transaction; rollback required", )); } - command(conn, "COMMIT")?; + commit_or_mark_unknown(conn, &mut state, true, "COMMIT")?; *state = TransactionState::default(); } else { command( @@ -529,7 +556,7 @@ unsafe fn execute(conn: *mut PgConnection, sql: &str) -> Result { } } if ends_transaction && rust_pq_transaction_status((*conn).conn) == 0 { - crate::descriptor_cache::transaction_ended(); + crate::descriptor_cache::connection_idle(conn as usize); } (*conn).last_error_code = 0; (*conn).last_error.fill(0); From d8c33f4871569d0357df56e8957676075d2e0b0d Mon Sep 17 00:00:00 2001 From: Sander Date: Sat, 7 Nov 2026 11:12:57 +0100 Subject: [PATCH 3/4] fix(shim): address second review round - publish-manual-docker keeps its own concurrency group: sharing the certified publisher's let a queued manual run replace a pending certified publication. The latest-release recheck before moving :latest stays, and a repository without releases no longer fails. - sqlite3_exec batches mark DDL even when the batch fails: an explicit COMMIT inside the batch can persist DDL before a later statement fails. - Every session reset (pool reset_conn, step read/write PQreset, handle session repair) ends that session's DDL window, so a reset cannot leave the description cache disabled. Co-Authored-By: Claude Opus 5.5 --- .github/workflows/publish-manual-docker.yml | 10 ++++++---- CHANGELOG.md | 2 +- rust/plex-pg-core/src/db_interpose_exec/pg_path.rs | 8 +++++--- .../first_execute/connection.rs | 1 + .../src/db_interpose_step_write_utils/connection.rs | 1 + .../plex-pg-core/src/pg_client/connection_lifecycle.rs | 2 ++ rust/plex-pg-core/src/pg_client/transaction.rs | 1 + 7 files changed, 17 insertions(+), 8 deletions(-) diff --git a/.github/workflows/publish-manual-docker.yml b/.github/workflows/publish-manual-docker.yml index d8586f2f..abefb1d0 100644 --- a/.github/workflows/publish-manual-docker.yml +++ b/.github/workflows/publish-manual-docker.yml @@ -20,9 +20,11 @@ on: permissions: contents: read -# Same group as the certified publisher: both may move :latest. +# Not the certified publisher's group: a queued manual run would replace a +# pending certified publication. The latest-release check right before +# moving :latest keeps the two from overwriting each other's image. concurrency: - group: certified-release-publication + group: manual-release-docker cancel-in-progress: false jobs: @@ -82,7 +84,7 @@ jobs: # :latest follows the repository's latest GitHub release, so a # manual publication of an older or newer-but-unreleased tag never # replaces the image of the current (possibly certified) release. - latest_release=$(gh release view --repo "$GITHUB_REPOSITORY" --json tagName --jq .tagName) + latest_release=$(gh release view --repo "$GITHUB_REPOSITORY" --json tagName --jq .tagName 2>/dev/null || true) publish() { local repository=$1 amd64=$2 arm64=$3 if docker buildx imagetools inspect "$repository:$TAG" >/dev/null 2>&1; then @@ -93,7 +95,7 @@ jobs: digest=$(docker buildx imagetools inspect "$repository:$TAG" | awk '/^Digest:/ {print $2; exit}') [[ "$digest" =~ ^sha256:[0-9a-f]{64}$ ]] # Re-read right before promoting in case a release was published meanwhile. - latest_release=$(gh release view --repo "$GITHUB_REPOSITORY" --json tagName --jq .tagName) + latest_release=$(gh release view --repo "$GITHUB_REPOSITORY" --json tagName --jq .tagName 2>/dev/null || true) if [[ "$latest_release" == "$TAG" ]]; then docker buildx imagetools create --tag "$repository:latest" "$repository@$digest" echo "$repository:$TAG and :latest -> $digest" >> "$GITHUB_STEP_SUMMARY" diff --git a/CHANGELOG.md b/CHANGELOG.md index afa0221d..d36ef0d8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -14,7 +14,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - A connection error noted during one step no longer makes the next failing statement on the same thread retry as if its connection had failed. - The result-description cache tracks uncommitted DDL per session: it resumes after DDL that ran outside a transaction, and another session's commit or autocommit write (or an inner `RELEASE SAVEPOINT`) no longer ends the window early. - A statement whose stream was read ahead is no longer re-run from the first row when it is stepped from another connection. -- Manual image publication only moves `:latest` when it publishes the repository's latest release, checked right before promotion, and runs serialised with the certified publisher. +- Manual image publication only moves `:latest` when it publishes the repository's latest release, checked right before promotion. ## [1.3.26] - 2026-11-06 diff --git a/rust/plex-pg-core/src/db_interpose_exec/pg_path.rs b/rust/plex-pg-core/src/db_interpose_exec/pg_path.rs index 6ad6a56a..6e2e06a1 100644 --- a/rust/plex-pg-core/src/db_interpose_exec/pg_path.rs +++ b/rust/plex-pg-core/src/db_interpose_exec/pg_path.rs @@ -260,8 +260,10 @@ pub(crate) fn exec_via_postgres( } let status = crate::libpq_helpers::rust_pq_result_status(res); + // Also on failure: a batch can commit DDL before a later + // statement fails. + note_write_done(pg_conn, CStr::from_ptr(sql).to_bytes(), true); if status == PGRES_COMMAND_OK || status == PGRES_TUPLES_OK { - note_write_done(pg_conn, CStr::from_ptr(sql).to_bytes(), true); clear_pg_last_error(pg_conn); let cmd_tuples = crate::libpq_helpers::rust_pq_cmd_tuples(res); let tuples_ptr = if cmd_tuples.is_null() { @@ -367,8 +369,8 @@ pub(crate) fn exec_via_postgres( } } -/// A write succeeded on `conn`. DDL opens a description-cache window that -/// ends once the session is idle; outside a transaction that is right away. +/// A write ran on `conn`. DDL opens a description-cache window that ends once +/// the session is idle; outside a transaction that is right away. pub(crate) fn note_write_done(conn: *mut crate::ffi_types::PgConnection, sql: &[u8], batch: bool) { if conn.is_null() { return; diff --git a/rust/plex-pg-core/src/db_interpose_step_read_utils/first_execute/connection.rs b/rust/plex-pg-core/src/db_interpose_step_read_utils/first_execute/connection.rs index 0c25eba1..2c000bfc 100644 --- a/rust/plex-pg-core/src/db_interpose_step_read_utils/first_execute/connection.rs +++ b/rust/plex-pg-core/src/db_interpose_step_read_utils/first_execute/connection.rs @@ -183,6 +183,7 @@ pub(super) unsafe fn ensure_connection_ready( log_error("=== END DIAGNOSTIC ==="); log_error("STEP READ: Attempting PQreset..."); crate::libpq_helpers::rust_pq_reset(ec.conn); + crate::descriptor_cache::connection_idle(exec_conn as usize); if crate::libpq_helpers::rust_pq_status(ec.conn) != CONNECTION_OK { log_error("STEP READ: PQreset failed, trying fresh PQconnectdb..."); diff --git a/rust/plex-pg-core/src/db_interpose_step_write_utils/connection.rs b/rust/plex-pg-core/src/db_interpose_step_write_utils/connection.rs index 5ed069a7..44f8e9d3 100644 --- a/rust/plex-pg-core/src/db_interpose_step_write_utils/connection.rs +++ b/rust/plex-pg-core/src/db_interpose_step_write_utils/connection.rs @@ -194,6 +194,7 @@ pub extern "C" fn rust_step_write_prepare_connection( log_error("=== END DIAGNOSTIC ==="); log_error("STEP WRITE: Attempting PQreset..."); crate::libpq_helpers::rust_pq_reset(ec.conn); + crate::descriptor_cache::connection_idle(exec_conn as usize); if crate::libpq_helpers::rust_pq_status(ec.conn) != CONNECTION_OK { log_error("STEP WRITE: PQreset failed, trying fresh PQconnectdb..."); crate::pg_client::rust_stmt_cache_clear(exec_conn as *mut c_void); diff --git a/rust/plex-pg-core/src/pg_client/connection_lifecycle.rs b/rust/plex-pg-core/src/pg_client/connection_lifecycle.rs index ea66ec14..fe6c59b4 100644 --- a/rust/plex-pg-core/src/pg_client/connection_lifecycle.rs +++ b/rust/plex-pg-core/src/pg_client/connection_lifecycle.rs @@ -194,6 +194,8 @@ pub(super) fn reset_conn(conn: *mut c_void) -> bool { return false; } rust_pq_reset(conn.conn); + // Whatever transaction the old session had is gone with it. + crate::descriptor_cache::connection_idle(conn_ptr as usize); if rust_pq_status(conn.conn) != CONNECTION_OK { return false; } diff --git a/rust/plex-pg-core/src/pg_client/transaction.rs b/rust/plex-pg-core/src/pg_client/transaction.rs index 57b5dfc7..1713a296 100644 --- a/rust/plex-pg-core/src/pg_client/transaction.rs +++ b/rust/plex-pg-core/src/pg_client/transaction.rs @@ -145,6 +145,7 @@ pub(crate) fn ensure_handle_session(conn: *mut PgConnection) { if !(*conn).conn.is_null() { if rust_pq_status((*conn).conn) != super::session::CONNECTION_OK { rust_pq_reset((*conn).conn); + crate::descriptor_cache::connection_idle(conn as usize); if rust_pq_status((*conn).conn) == super::session::CONNECTION_OK { super::session::pg_set_socket_timeout((*conn).conn); super::session::apply_session_settings((*conn).conn, &config.schema, false); From 84c1050b314acc5f2d688d71a8aa8b08f3c84c31 Mon Sep 17 00:00:00 2001 From: Sander Date: Sat, 7 Nov 2026 11:15:55 +0100 Subject: [PATCH 4/4] ci: decide :latest before writing tags in manual image publication Third review round: the latest-release recheck between writing the version tag and :latest still raced a certified publication, and suppressed API errors turned into a silent partial success that could not be rerun. The decision is now made before any tag is written, errors fail the run, and :latest is left alone while a certified publication is running. Co-Authored-By: Claude Opus 5.5 --- .github/workflows/publish-manual-docker.yml | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/.github/workflows/publish-manual-docker.yml b/.github/workflows/publish-manual-docker.yml index abefb1d0..7e5a2261 100644 --- a/.github/workflows/publish-manual-docker.yml +++ b/.github/workflows/publish-manual-docker.yml @@ -84,7 +84,17 @@ jobs: # :latest follows the repository's latest GitHub release, so a # manual publication of an older or newer-but-unreleased tag never # replaces the image of the current (possibly certified) release. - latest_release=$(gh release view --repo "$GITHUB_REPOSITORY" --json tagName --jq .tagName 2>/dev/null || true) + # Decided before any tag is written (an API error fails the run + # while it can still be rerun), and only while no certified + # publication is running, which would set :latest itself. + latest_release=$(gh release list --repo "$GITHUB_REPOSITORY" --exclude-drafts --exclude-pre-releases \ + --limit 20 --json tagName,isLatest --jq '[.[] | select(.isLatest)][0].tagName // ""') + certified_publications=$(gh run list --repo "$GITHUB_REPOSITORY" --workflow publish-certified-release.yml \ + --limit 10 --json status --jq '[.[] | select(.status != "completed")] | length') + move_latest=false + if [[ "$latest_release" == "$TAG" && "$certified_publications" == 0 ]]; then + move_latest=true + fi publish() { local repository=$1 amd64=$2 arm64=$3 if docker buildx imagetools inspect "$repository:$TAG" >/dev/null 2>&1; then @@ -94,13 +104,11 @@ jobs: docker buildx imagetools create --tag "$repository:$TAG" "$amd64" "$arm64" digest=$(docker buildx imagetools inspect "$repository:$TAG" | awk '/^Digest:/ {print $2; exit}') [[ "$digest" =~ ^sha256:[0-9a-f]{64}$ ]] - # Re-read right before promoting in case a release was published meanwhile. - latest_release=$(gh release view --repo "$GITHUB_REPOSITORY" --json tagName --jq .tagName 2>/dev/null || true) - if [[ "$latest_release" == "$TAG" ]]; then + if [[ "$move_latest" == true ]]; then docker buildx imagetools create --tag "$repository:latest" "$repository@$digest" echo "$repository:$TAG and :latest -> $digest" >> "$GITHUB_STEP_SUMMARY" else - echo "$repository:$TAG -> $digest (:latest left on $latest_release)" >> "$GITHUB_STEP_SUMMARY" + echo "$repository:$TAG -> $digest (:latest unchanged; latest release ${latest_release:-none})" >> "$GITHUB_STEP_SUMMARY" fi } publish ghcr.io/cgnl/plex-postgresql-linuxserver "$LINUXSERVER_AMD64" "$LINUXSERVER_ARM64"