Skip to content

fix(tls): potential deadlock in StdSocket::poll_ready() - #4251

Merged
abonander merged 1 commit into
mainfrom
ab/fix-tls-deadlock
Apr 28, 2026
Merged

abonander merged 1 commit into
mainfrom
ab/fix-tls-deadlock

Conversation

@abonander

@abonander abonander commented Apr 28, 2026 •

Copy link
Copy Markdown
Collaborator

Does your PR solve an issue?

Changes StdSocket::poll_ready() to schedule wakeups for both reads and writes where applicable, and return if either direction is ready, not necessarily both.

Previously, if the TLS code, e.g. rustls::Connection::complete_io() tried to both read and write on the socket, poll_ready() would wait for the connection to be ready in both directions. This was prone to deadlocking if the server-side was waiting to receive more data before it sent any, e.g. it was waiting for us to write a full Execute packet so it could start executing a query and feeding back results.

poll_ready() now returns Ready if either direction is ready even if the other direction is blocked, letting the TLS implementation do as much I/O as possible before going to sleep and hopefully preventing deadlocks of this kind.

fixes #4248

This likely fixes a number of other hang/deadlock-related issues as well, but I'd need to find them.

Is this a breaking change?

No.

@abonander

Copy link
Copy Markdown
Collaborator Author

@jcreekmore can you try this branch and see if it also eliminates the issue? I changed poll_ready() to schedule wakeups for both reads and writes where applicable.

@jcreekmore

Copy link
Copy Markdown

It also eliminates the issue. I technically didn't run this branch, but I cherry-picked the change on top of 0.8.6 so that I didn't have to worry about pulling in any other changes that have occurred in the interim.

@abonander
abonander merged commit c0ec9c0 into main Apr 28, 2026
147 checks passed
@abonander
abonander deleted the ab/fix-tls-deadlock branch April 28, 2026 23:37
kiwidream added a commit to Qbit-Org/qbit-mining-bootstrap that referenced this pull request Oct 28, 2026
… vendoring sqlx-core 0.8.6 (#771) (#794)

* 3.x.x: backport sqlx's TLS readiness fix so a large statement cannot stall a ledger connection (#771)

Cause. sqlx-core 0.8.6's StdSocket::poll_ready, under every rustls
connection, waited for write readiness and then for read readiness.
When a write blocks before sending anything, rustls 0.23.46's
complete_io tries a read too, so a large statement leaves both flagged.
Write readiness that arrives between the blocked write and the poll is
spent, and the task parks on read readiness while the server waits for
the rest of the statement (#765's suspected stall). Data that arrives
while the task waits to write has no waker at all. transact-rs/sqlx#4251 (merge c0ec9c0b, 2026-04-28) fixes
both: poll_ready registers both directions and returns when either is
ready. It is released in sqlx 0.9.0 only; no 0.8.x tag carries it.

Change.
- vendor/sqlx-core is sqlx-core 0.8.6 from the local registry cache,
  identical to the crates.io .crate whose SHA-256 the lockfile recorded
  (ee6798b1), plus #4251's diff to src/net/tls/util.rs and a README with
  the provenance. The diff applies as upstream wrote it; its import
  context differs only because 0.8.6 takes `future` from futures_util.
- The root Cargo.toml and the fuzz workspace's Cargo.toml patch
  sqlx-core to it. Both lockfiles change only in dropping sqlx-core's
  registry source and checksum; the root one also lists the test's two
  dev-dependencies, already in the graph.
- lab/prism/Dockerfile copies vendor/ into the build stage: without it
  the image's build context no longer resolves.
- tests/sqlx_tls_readiness.rs runs sqlx-core's rustls client against a
  rustls server over an in-memory socket whose readiness it controls,
  polling by hand. One case frees the send buffer between the blocked
  write and the readiness poll; the other has the server send while the
  client waits to write and read nothing more until the client reads.
  Against unpatched 0.8.6 both stall (parked on read with no write waker,
  and on write with no read waker); with the backport both finish, and the
  server receives the request byte for byte.

Not changed: #770's `repolled` in import-audits stays, sslmode handling
(#713) is untouched, and the vendored crate's three upstream
mismatched_lifetime_syntaxes warnings are left as shipped.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* 3.x.x: guard the vendored sqlx-core patch and its advisories in CI (#771)

Review follow-up to the backport.

The patch. sqlx pins its sqlx-core with `=`, so moving sqlx to another
0.8.x leaves `[patch.crates-io]` unused: Cargo only warns, the unfixed
crates.io sqlx-core returns, and nothing in the fuzz workspace would
notice. scripts/check_vendored_sqlx_core.py fails unless, for the
repository and the fuzz workspace alike:
- Cargo.toml patches sqlx-core to vendor/sqlx-core;
- Cargo.lock holds one sqlx-core, with no source or checksum, at the
  vendored version;
- the locked sqlx is that version too (sqlx X requires sqlx-core =X), and
  its sqlx-core dependency names no other copy;
- the lock file does not record the patch under [[patch.unused]].
The lint job runs it beside the other check scripts.

Advisories. cargo-deny matches RustSec advisories only against registry
crates, so it stopped checking sqlx-core. Right after `cargo deny check`,
the cargo-deny job runs the same script with --require-advisory-db.
- The script finds the database cargo-deny fetched from deny.toml's
  db-path, or from --advisory-db / RUSTSEC_ADVISORY_DB.
- It lists every sqlx-core advisory there and fails on any that is not
  withdrawn and not named, with a one-line reason, in
  vendor/sqlx-core/reviewed-advisories.toml.
- The database of 2026-10-28 holds none, so the list is empty.
The vendored README explains both checks and what to do when an
advisory appears. tests/test_check_vendored_sqlx_core.py covers:
- a registry or hand-edited sqlx-core in either lock;
- sqlx moved past the vendored version, with the patch unused;
- a second sqlx-core;
- a missing or misdirected patch;
- unreviewed, reviewed, withdrawn and malformed advisories;
- the database's location;
- the CI wiring.

The test. Its sqlx-core dev-dependency is pinned to =0.8.6, with the
_tls-rustls-ring-webpki feature that sqlx's runtime-tokio-rustls
enables. Moving sqlx or the test's backend then fails resolution or the
test instead of testing another copy. The first case no longer asserts
that a drain finds no write waker. A drain now wakes one it finds, as an
I/O driver would, and the test requires at least one drain that found
none: that is the lost-wakeup window. The module comment states the
dependency on rustls 0.23.46's complete_io, and how to re-validate the
harness on a rustls bump. Against the unpatched util.rs both cases still
stall.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

---------

Co-authored-by: Claude Opus 5.5 <[email protected]>
kiwidream added a commit to Qbit-Org/qbit-mining-bootstrap that referenced this pull request Nov 12, 2026
…and CI checks vendored sqlx-core against upstream's .crate plus recorded patches (#825)

## Problem

#825 items 1 and 2, from #818's and #794's reviews:

1. **verify-ca without a root certificate passes startup.** Since #818, sqlx-postgres refuses every `sslmode=verify-ca` connect that has no `sslrootcert` (or `PGSSLROOTCERT`). But nothing at startup checked for it, so a `PRISM_DATABASE_URL` or peer URL like that passed `check-config` and startup, then failed every connect.
2. **Nothing ties `vendor/sqlx-core` to upstream.** `check_vendored_sqlx_core.py` checked that both lock files build the vendored copy and that its advisories are reviewed. It never checked the files, so an unrecorded edit to the vendored TLS code would pass CI.

## Change

### Startup refuses verify-ca without a root certificate (item 1)

- **Which settings.** `PRISM_DATABASE_URL` (frontend, `check-config`, the database commands and the public reader) and `PRISM_PEER_DATABASE_URL` / `PRISM_PEER_DATABASE_URL_FALLBACK` (the dual writer). Each is refused by name, with the connect's own message:
  > sslmode=verify-ca requires sslrootcert: verify-ca does not check the server's host name, so it trusts only the root certificates in sslrootcert, never the public roots; set sslrootcert, or use sslmode=verify-full
- **Resolved as the connect resolves them.** The mode and certificate come from SQLx's `PgConnectOptions::from_url`, the parser the connect itself uses, so there is no second parser: the URL's `sslmode` and `sslrootcert` win over `PGSSLMODE` and `PGSSLROOTCERT`. `ssl_root_cert` has no getter, so it is read back through `to_url_lossy()`, as the existing password check already does. An empty `sslrootcert` names no file, so it counts as none. The certificate file is not read here; a missing or unusable file is still the connect's error, as before.
- **Other modes are unchanged:** `verify-full`, `require`, `prefer`, `allow` and `disable`.
- **One more refusal.** `PRISM_DATABASE_URL` is now parsed with the client's parser, as the peer URLs already were. A URL the client can't use (for example `sslmode=sometimes`) is refused at startup, by name, instead of at the first connect.
- **`make doctor` shows it.** `scripts/check-env.sh` relays only known, value-free public-reader errors, so the new refusal showed as a generic image error. It now relays `public PRISM_DATABASE_URL: sslmode=verify-ca requires sslrootcert`.

### CI checks vendored sqlx-core against upstream's `.crate` plus recorded patches (item 2)

- **The recorded changes are patches.** `vendor/sqlx-core.patches/` holds one `diff -u` patch per change, each with a description above it:
  - `0001-sqlx-4251-poll-ready-waits-on-either-direction.patch` (transact-rs/sqlx#4251, #771);
  - `0002-sqlx-3861-verify-ca-accepts-not-valid-for-name-context.patch` (transact-rs/sqlx#3861, #713);
  - `0003-verify-ca-trusts-only-sslrootcert.patch` (the local change, #818).
- **CI rebuilds the tree from upstream and compares.** The step that checks the lock files now downloads `sqlx-core-0.8.6.crate` from static.crates.io, as the alert step downloads promtool. The checker:
  - refuses the `.crate` unless its SHA-256 is the `ee6798b1…68dc6` that `vendor/sqlx-core/README.md` records, and reads it in memory, never extracting it;
  - applies the patches in name order, each hunk only at the line it names and on exact context, with no offset and no fuzz;
  - accepts `\ No newline at end of file` only on a file's last line, so a marker can't join a line onto the next one that review reads as separate;
  - allows free text only before a patch's first file, and refuses anything else outside the hunks;
  - fails unless the result is `vendor/sqlx-core` byte for byte: no file differs, none is missing, none is a symbolic link, and none is added but `README.md` and `reviewed-advisories.toml`. The build reads neither of those: `Cargo.toml` names no `readme` or build script, and no source includes them.
- **A change to a patched file has to change its patch.** The review's edit, `tls_rustls.rs`'s verify-ca store to `let mut cert_store = public_roots();`, now fails. It passes only once a patch records it.
- **Recording a change.** `--unrecorded-diff` prints what the tree changes beyond the recorded patches, as the next patch. The README's "Changing this copy" gives the steps.
- **Two README rules.** The README must record the `.crate`'s SHA-256 exactly once, and it must name every patch file. The second keeps its change list in step with the patches; it checks nothing the README says.
- **Locally, no flag needed.** Without `--upstream-crate`, the script uses Cargo's cached `.crate` if there is one. Without one, it skips the source check and says so.
- **The Python tests use the real crate too.** The `python-tests` job downloads the same `.crate` and names it in `SQLX_CORE_UPSTREAM_CRATE`, so the real-tree tests run in CI. If it is named but missing, they fail rather than skip.
- **The manifest is gone.** I kept the earlier offline premise until review showed it was false: `ci.yml` already downloads promtool. The patch check covers everything `vendor/sqlx-core.sha256` did. The manifest's only extra was working without the `.crate`, which CI now always has. And its upstream/patched/added labels were the part offline CI could not check. Removing it also removes `--write-manifest` and its README gate, which a whitespace edit or a deleted manifest got past.

**What this proves, and what it doesn't.**
- **It proves** that `vendor/sqlx-core` is upstream 0.8.6 plus the recorded patches, byte for byte.
- **It doesn't judge the patches.** A patch that trusted the public roots again would pass, and so would a commit that changed both the code and its patch.
- **The control is review.** Review every change under `vendor/sqlx-core.patches/`, where each change to the vendored code is a diff against upstream. `sqlx_tls_verify_ca.rs` and `sqlx_tls_readiness.rs` check what the three changes do.
- **Two files are unchecked:** edits to the README and to `reviewed-advisories.toml`.

The README says the same.

## Tests run

All local. The Python checks and guards ran again on this head, after merging 3.x.x:

- **Vendored source:** `python3 -m unittest -v tests.test_check_vendored_sqlx_core`: 19 passed. I ran it with `SQLX_CORE_UPSTREAM_CRATE` set to a `.crate` freshly downloaded from static.crates.io, as CI sets it, and again with Cargo's cached copy. With the variable naming a missing file, the two real-tree tests fail. The tests cover:
  - the real tree is 0.8.6 plus the 3 patches: 4 of 100 files patched, README.md and reviewed-advisories.toml added;
  - the review's `public_roots()` edit to the real `tls_rustls.rs` fails, and passes only once its `--unrecorded-diff` is saved as a patch;
  - each of these fails: an edited upstream file, a patched file changed beyond its patch, a removed patch, an added source file, an added `build.rs`, `.cargo-ok`, a missing upstream file, a symbolic link, and a `.crate` other than the README's;
  - each of these patches is refused:
    - a hunk at another line, on other context, or with a `+` start that disagrees;
    - an insertion past a file's end, and a no-newline marker that joins two lines, even when the tree matches what a lenient applier makes of them;
    - a patch that creates a file, or touches a file upstream lacks or one outside the crate;
    - timestamps, two paths, short, long or miscounted hunks, text between hunks, a malformed header, or a hunk before any file;
    - no hunks, a file named twice, no final newline, or no file at all;
    - a stray file, an upper-case name, a symlink or a directory in `vendor/sqlx-core.patches/`;
  - a last line without a newline, on either side, round-trips through `--unrecorded-diff`;
  - edits to the README and to `reviewed-advisories.toml` pass. A README that records two `.crate` SHA-256s fails, and so does one that doesn't name a patch (without the hint to record a patch);
  - a `.crate` whose version is not the vendored `Cargo.toml`'s fails, and the error names the version;
  - without `--upstream-crate`, the script checks against Cargo's cached `.crate`, and skips the source check when there is none;
  - `ci.yml` downloads the `.crate` before the check and the Python shard, and passes it to both.
- **CI's step, run locally as written** (with `RUNNER_TEMP` set): it downloaded the `.crate` (SHA-256 `ee6798b1…68dc6`) and the check passed.
- **check-env:** `python3 -m unittest -v tests.test_check_env_public_credentials`: 13 passed. The new relay test fails without the `check-env.sh` line.
- **Startup, through the real binary** (unchanged by the follow-up commit; run on `d3cb5a92`):
  - `cargo test --locked -p qbit-prism-server --test config_cli --no-fail-fast`: 32 passed.
    - `verify_ca_without_a_root_certificate_fails_before_startup`: 10 cases over the three URL settings, covering `sslrootcert` absent or empty, `PGSSLROOTCERT`, `PGSSLMODE`, verify-full and require.
    - `startup_refuses_verify_ca_with_the_message_the_connect_gives`: startup's error equals `PgConnection::connect`'s, against a fake server that answers the SSLRequest with `S` and then sees no further byte.
  - `cargo test --locked -p qbit-prism-server --test public_database_config --no-fail-fast`: 6 passed, through `check-public-database-config` and `public-api`.
  - `cargo test --locked -p qbit-prism-server --lib config::`: 13 passed.
  - With the check disabled, the new verify-ca tests fail.
  - `cargo fmt --all -- --check` passes. `cargo clippy --locked -p qbit-prism-server --all-targets -- -D warnings` passes, apart from the three known `mismatched_lifetime_syntaxes` warnings in vendored sqlx-core.
- **Guards:** `check_vendored_sqlx_core.py --upstream-crate <.crate>`, `check_prism_pool_acquires.py`, `check_gate_env_reads.py`, `check_prism_settings.py`, `check_deleted_test_map.py` and `check_toolchain_pin.py` all pass. `bash -n scripts/check-env.sh` passes, and the workflow parses as YAML.

No new PostgreSQL-gated tests, settings or deleted tests.

## CI

- **Correction to this PR's first body.** CI does run `tests/test_check_vendored_sqlx_core.py`: `run_python_test_shard.py` discovers `tests/test_*.py`, and run 41738227640's shard 2 ran all 18 of the earlier tests. Its upstream test was skipped there because no `.crate` was cached. The `python-tests` job now downloads one.
- **What CI runs.** The lint job's vendored-sqlx-core step runs the source check against the downloaded `.crate`. CI's full suites cover the rest of `qbit-prism-server`.

## Known, and out of scope

- **A whitespace-only `sslrootcert`** passes the startup check. The connect still refuses it.
- **Some `tools.rs` commands skip the startup check.** They read the database URLs directly:
  - `fatal-state show` (`tools.rs:902`)
  - `submission-hold show` (`:1142`)
  - `candidates list` (`:1242`)
  - recover planning (`:1410`)
  - node-identity repersonalise's peer URLs (`:971-976`)

  The connect still refuses each with the same message.
- **`policy-transition`** checks the target configuration with the process's own `PG*` environment. It applies only the `PRISM_` and `QBIT_` settings from its `--to` file, and it can't change `PRISM_DATABASE_URL` anyway.

Item 3 (the release notes rewrite) is #832. Items 4 and 5 are not in this PR.

Refs #825

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Squashed commits:
d3cb5a9 3.x.x: startup refuses sslmode=verify-ca without a root certificate, and CI checks every vendored sqlx-core file against a manifest (#825)
3a7cfc8 3.x.x: CI checks vendored sqlx-core against upstream's .crate plus recorded patches, and doctor relays the verify-ca refusal (#825)
a078cba Merge remote-tracking branch 'origin/3.x.x' into orca/825-release-and-tls-guards
a18fba8 3.x.x: a vendored sqlx-core patch applies only as it reads: no line joined by a no-newline marker, no insertion past the end (#825)

Co-Authored-By: Claude Opus 5.5 <[email protected]>
kiwidream added a commit to Qbit-Org/qbit-mining-bootstrap that referenced this pull request Nov 13, 2026
…and CI checks vendored sqlx-core against upstream's .crate plus recorded patches (#825)

## Problem

#825 items 1 and 2, from #818's and #794's reviews:

1. **verify-ca without a root certificate passes startup.** Since #818, sqlx-postgres refuses every `sslmode=verify-ca` connect that has no `sslrootcert` (or `PGSSLROOTCERT`). But nothing at startup checked for it, so a `PRISM_DATABASE_URL` or peer URL like that passed `check-config` and startup, then failed every connect.
2. **Nothing ties `vendor/sqlx-core` to upstream.** `check_vendored_sqlx_core.py` checked that both lock files build the vendored copy and that its advisories are reviewed. It never checked the files, so an unrecorded edit to the vendored TLS code would pass CI.

## Change

### Startup refuses verify-ca without a root certificate (item 1)

- **Which settings.** `PRISM_DATABASE_URL` (frontend, `check-config`, the database commands and the public reader) and `PRISM_PEER_DATABASE_URL` / `PRISM_PEER_DATABASE_URL_FALLBACK` (the dual writer). Each is refused by name, with the connect's own message:
  > sslmode=verify-ca requires sslrootcert: verify-ca does not check the server's host name, so it trusts only the root certificates in sslrootcert, never the public roots; set sslrootcert, or use sslmode=verify-full
- **Resolved as the connect resolves them.** The mode and certificate come from SQLx's `PgConnectOptions::from_url`, the parser the connect itself uses, so there is no second parser: the URL's `sslmode` and `sslrootcert` win over `PGSSLMODE` and `PGSSLROOTCERT`. `ssl_root_cert` has no getter, so it is read back through `to_url_lossy()`, as the existing password check already does. An empty `sslrootcert` names no file, so it counts as none. The certificate file is not read here; a missing or unusable file is still the connect's error, as before.
- **Other modes are unchanged:** `verify-full`, `require`, `prefer`, `allow` and `disable`.
- **One more refusal.** `PRISM_DATABASE_URL` is now parsed with the client's parser, as the peer URLs already were. A URL the client can't use (for example `sslmode=sometimes`) is refused at startup, by name, instead of at the first connect.
- **`make doctor` shows it.** `scripts/check-env.sh` relays only known, value-free public-reader errors, so the new refusal showed as a generic image error. It now relays `public PRISM_DATABASE_URL: sslmode=verify-ca requires sslrootcert`.

### CI checks vendored sqlx-core against upstream's `.crate` plus recorded patches (item 2)

- **The recorded changes are patches.** `vendor/sqlx-core.patches/` holds one `diff -u` patch per change, each with a description above it:
  - `0001-sqlx-4251-poll-ready-waits-on-either-direction.patch` (transact-rs/sqlx#4251, #771);
  - `0002-sqlx-3861-verify-ca-accepts-not-valid-for-name-context.patch` (transact-rs/sqlx#3861, #713);
  - `0003-verify-ca-trusts-only-sslrootcert.patch` (the local change, #818).
- **CI rebuilds the tree from upstream and compares.** The step that checks the lock files now downloads `sqlx-core-0.8.6.crate` from static.crates.io, as the alert step downloads promtool. The checker:
  - refuses the `.crate` unless its SHA-256 is the `ee6798b1…68dc6` that `vendor/sqlx-core/README.md` records, and reads it in memory, never extracting it;
  - applies the patches in name order, each hunk only at the line it names and on exact context, with no offset and no fuzz;
  - accepts `\ No newline at end of file` only on a file's last line, so a marker can't join a line onto the next one that review reads as separate;
  - allows free text only before a patch's first file, and refuses anything else outside the hunks;
  - fails unless the result is `vendor/sqlx-core` byte for byte: no file differs, none is missing, none is a symbolic link, and none is added but `README.md` and `reviewed-advisories.toml`. The build reads neither of those: `Cargo.toml` names no `readme` or build script, and no source includes them.
- **A change to a patched file has to change its patch.** The review's edit, `tls_rustls.rs`'s verify-ca store to `let mut cert_store = public_roots();`, now fails. It passes only once a patch records it.
- **Recording a change.** `--unrecorded-diff` prints what the tree changes beyond the recorded patches, as the next patch. The README's "Changing this copy" gives the steps.
- **Two README rules.** The README must record the `.crate`'s SHA-256 exactly once, and it must name every patch file. The second keeps its change list in step with the patches; it checks nothing the README says.
- **Locally, no flag needed.** Without `--upstream-crate`, the script uses Cargo's cached `.crate` if there is one. Without one, it skips the source check and says so.
- **The Python tests use the real crate too.** The `python-tests` job downloads the same `.crate` and names it in `SQLX_CORE_UPSTREAM_CRATE`, so the real-tree tests run in CI. If it is named but missing, they fail rather than skip. The download carries the same-tree skip's condition (#839), like the job's other steps, so a run that skips the shard skips it too.
- **The manifest is gone.** I kept the earlier offline premise until review showed it was false: `ci.yml` already downloads promtool. The patch check covers everything `vendor/sqlx-core.sha256` did. The manifest's only extra was working without the `.crate`, which CI now always has. And its upstream/patched/added labels were the part offline CI could not check. Removing it also removes `--write-manifest` and its README gate, which a whitespace edit or a deleted manifest got past.

**What this proves, and what it doesn't.**
- **It proves** that `vendor/sqlx-core` is upstream 0.8.6 plus the recorded patches, byte for byte.
- **It doesn't judge the patches.** A patch that trusted the public roots again would pass, and so would a commit that changed both the code and its patch.
- **The control is review.** Review every change under `vendor/sqlx-core.patches/`, where each change to the vendored code is a diff against upstream. `sqlx_tls_verify_ca.rs` and `sqlx_tls_readiness.rs` check what the three changes do.
- **Two files are unchecked:** edits to the README and to `reviewed-advisories.toml`.

The README says the same.

## Tests run

All local. The Python checks and guards ran again on this head, after merging 3.x.x:

- **Vendored source:** `python3 -m unittest -v tests.test_check_vendored_sqlx_core`: 19 passed. I ran it with `SQLX_CORE_UPSTREAM_CRATE` set to a `.crate` freshly downloaded from static.crates.io, as CI sets it, and again with Cargo's cached copy. With the variable naming a missing file, the two real-tree tests fail. The tests cover:
  - the real tree is 0.8.6 plus the 3 patches: 4 of 100 files patched, README.md and reviewed-advisories.toml added;
  - the review's `public_roots()` edit to the real `tls_rustls.rs` fails, and passes only once its `--unrecorded-diff` is saved as a patch;
  - each of these fails: an edited upstream file, a patched file changed beyond its patch, a removed patch, an added source file, an added `build.rs`, `.cargo-ok`, a missing upstream file, a symbolic link, and a `.crate` other than the README's;
  - each of these patches is refused:
    - a hunk at another line, on other context, or with a `+` start that disagrees;
    - an insertion past a file's end, and a no-newline marker that joins two lines, even when the tree matches what a lenient applier makes of them;
    - a patch that creates a file, or touches a file upstream lacks or one outside the crate;
    - timestamps, two paths, short, long or miscounted hunks, text between hunks, a malformed header, or a hunk before any file;
    - no hunks, a file named twice, no final newline, or no file at all;
    - a stray file, an upper-case name, a symlink or a directory in `vendor/sqlx-core.patches/`;
  - a last line without a newline, on either side, round-trips through `--unrecorded-diff`;
  - edits to the README and to `reviewed-advisories.toml` pass. A README that records two `.crate` SHA-256s fails, and so does one that doesn't name a patch (without the hint to record a patch);
  - a `.crate` whose version is not the vendored `Cargo.toml`'s fails, and the error names the version;
  - without `--upstream-crate`, the script checks against Cargo's cached `.crate`, and skips the source check when there is none;
  - `ci.yml` downloads the `.crate` before the check and the Python shard, and passes it to both.
- **CI's step, run locally as written** (with `RUNNER_TEMP` set): it downloaded the `.crate` (SHA-256 `ee6798b1…68dc6`) and the check passed.
- **check-env:** `python3 -m unittest -v tests.test_check_env_public_credentials`: 13 passed. The new relay test fails without the `check-env.sh` line.
- **Startup, through the real binary** (unchanged by the follow-up commit; run on `d3cb5a92`):
  - `cargo test --locked -p qbit-prism-server --test config_cli --no-fail-fast`: 32 passed.
    - `verify_ca_without_a_root_certificate_fails_before_startup`: 10 cases over the three URL settings, covering `sslrootcert` absent or empty, `PGSSLROOTCERT`, `PGSSLMODE`, verify-full and require.
    - `startup_refuses_verify_ca_with_the_message_the_connect_gives`: startup's error equals `PgConnection::connect`'s, against a fake server that answers the SSLRequest with `S` and then sees no further byte.
  - `cargo test --locked -p qbit-prism-server --test public_database_config --no-fail-fast`: 6 passed, through `check-public-database-config` and `public-api`.
  - `cargo test --locked -p qbit-prism-server --lib config::`: 13 passed.
  - With the check disabled, the new verify-ca tests fail.
  - `cargo fmt --all -- --check` passes. `cargo clippy --locked -p qbit-prism-server --all-targets -- -D warnings` passes, apart from the three known `mismatched_lifetime_syntaxes` warnings in vendored sqlx-core.
- **Guards:** `check_vendored_sqlx_core.py --upstream-crate <.crate>`, `check_prism_pool_acquires.py`, `check_gate_env_reads.py`, `check_prism_settings.py`, `check_deleted_test_map.py` and `check_toolchain_pin.py` all pass. `bash -n scripts/check-env.sh` passes, and the workflow parses as YAML.

No new PostgreSQL-gated tests, settings or deleted tests.

## CI

- **Correction to this PR's first body.** CI does run `tests/test_check_vendored_sqlx_core.py`: `run_python_test_shard.py` discovers `tests/test_*.py`, and run 41738227640's shard 2 ran all 18 of the earlier tests. Its upstream test was skipped there because no `.crate` was cached. The `python-tests` job now downloads one.
- **What CI runs.** The lint job's vendored-sqlx-core step runs the source check against the downloaded `.crate`. CI's full suites cover the rest of `qbit-prism-server`.

## Known, and out of scope

- **A whitespace-only `sslrootcert`** passes the startup check. The connect still refuses it.
- **Some `tools.rs` commands skip the startup check.** They read the database URLs directly:
  - `fatal-state show` (`tools.rs:902`)
  - `submission-hold show` (`:1142`)
  - `candidates list` (`:1242`)
  - recover planning (`:1410`)
  - node-identity repersonalise's peer URLs (`:971-976`)

  The connect still refuses each with the same message.
- **`policy-transition`** checks the target configuration with the process's own `PG*` environment. It applies only the `PRISM_` and `QBIT_` settings from its `--to` file, and it can't change `PRISM_DATABASE_URL` anyway.

Item 3 (the release notes rewrite) is #832. Items 4 and 5 are not in this PR.

Refs #825

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Squashed commits:
af6780d 3.x.x: startup refuses sslmode=verify-ca without a root certificate, and CI checks vendored sqlx-core against upstream's .crate plus recorded patches (#825)
64ee188 Merge remote-tracking branch 'origin/3.x.x' into orca/825-release-and-tls-guards
12b8887 3.x.x: python-tests downloads upstream sqlx-core only in a run that runs the shard (#825)

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

race polling a tls connection using sqlx-mysql

2 participants