{"record":{"id":"f99dd88616d8d074","repo":"bytebase/bytebase","slug":"failed-to-inspect-sample-instance-setup-deletion","errorCode":null,"errorMessage":"failed to inspect sample instance setup deletion","messagePattern":"failed to inspect sample instance setup deletion","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"backend/store/sample_instance.go","lineNumber":316,"sourceCode":"\tif err := tx.Commit(); err != nil {\n\t\treturn nil, errors.Wrap(err, \"failed to commit sample instance cleanup\")\n\t}\n\treturn result, nil\n}\n\n// MarkDeleted marks an activated setup physically removed.\nfunc (tx *SampleInstanceSetupTx) MarkDeleted(ctx context.Context, deletedAt time.Time) error {\n\tresult, err := tx.tx.ExecContext(ctx, `\n\t\tUPDATE sample_instance_setup SET deleted_at = $1, updated_at = $1\n\t\tWHERE workspace = $2 AND replica_id = $3\n\t\t\tAND activated_at IS NOT NULL AND deleted_at IS NULL\n\t`, deletedAt, tx.workspace, tx.replica)\n\tif err != nil {\n\t\treturn errors.Wrap(err, \"failed to mark sample instance setup deleted\")\n\t}\n\trows, err := result.RowsAffected()\n\tif err != nil {\n\t\treturn errors.Wrap(err, \"failed to inspect sample instance setup deletion\")\n\t}\n\tif rows != 1 {\n\t\treturn errors.Errorf(\"sample instance setup %q cannot be marked deleted\", tx.workspace)\n\t}\n\treturn nil\n}\n\n// DeleteReservation removes the locked pending setup.\nfunc (tx *SampleInstanceSetupTx) DeleteReservation(ctx context.Context) error {\n\tresult, err := tx.tx.ExecContext(ctx, `\n\t\tDELETE FROM sample_instance_setup\n\t\tWHERE workspace = $1 AND replica_id = $2\n\t\t\tAND activated_at IS NULL AND deleted_at IS NULL\n\t`, tx.workspace, tx.replica)\n\tif err != nil {\n\t\treturn errors.Wrap(err, \"failed to delete sample instance setup reservation\")\n\t}\n\trows, err := result.RowsAffected()","sourceCodeStart":298,"sourceCodeEnd":334,"githubUrl":"https://github.com/bytebase/bytebase/blob/1870550677fe08f0d2a78c07acd27541464eb945/backend/store/sample_instance.go#L298-L334","documentation":"This error wraps a failure from result.RowsAffected() after the MarkDeleted UPDATE on sample_instance_setup. The UPDATE executed, but the driver could not report how many rows it changed. This is a driver/protocol-level failure, not a data problem.","triggerScenarios":"Calling MarkDeleted when result.RowsAffected() returns an error from the pq/pgxc driver — typically because the underlying connection was closed or the command tag could not be parsed after a connection-level failure.","commonSituations":"Connection dropped between the UPDATE and the RowsAffected call; using a driver that does not support RowsAffected for the statement; unusual proxy/pooler (e.g. pgbouncer in statement mode) mangling the command tag.","solutions":["Check DB connection stability; reconnect and retry the cleanup sweep.","If behind PgBouncer or another pooler, ensure a mode that preserves command tags (session/transaction pooling) and server-side affected-row reporting.","Update the Postgres driver to a current version.","Inspect the wrapped error for the driver-level cause.","Retry — the cleanup sweep is idempotent under FOR UPDATE SKIP LOCKED."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"if err := tx.MarkDeleted(ctx, now); err != nil {\n\tif strings.Contains(err.Error(), \"failed to inspect sample instance setup deletion\") {\n\t\tlog.Printf(\"driver could not report rows affected; retry sweep\")\n\t}\n\treturn err\n}","preventionTips":["Use a current pgx/lib/pq driver","Avoid statement-mode poolers that drop command tags","Monitor connection drops to the metadata DB","Retry the idempotent cleanup sweep"],"tags":["database","driver","rows-affected"],"backgroundTag":"database-query-failed","analyzedSha":"1870550677fe08f0d2a78c07acd27541464eb945","analyzedAt":"2026-09-06T21:16:13.665Z","contentChangedAt":"2026-09-06T21:16:13.665Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}