Repository navigation
Description
Package
mysql-proxy (WordPress/sqlite-database-integration), against trunk (70bdaf3).
Summary
All concurrent MySQL client sessions share a single Adapter instance — and therefore a single underlying database connection — so per-connection state leaks between clients.
MySQL_Proxy::__construct()accepts oneAdapterand stores it (packages/mysql-proxy/src/class-mysql-proxy.php).- For every new client,
MySQL_Proxycreates the session with that same instance:new MySQL_Session( $this->adapter, $client_id, ... ). - The bundled
SQLite_Adapter(packages/mysql-proxy/src/Adapter/class-sqlite-adapter.php) holds exactly oneWP_MySQL_On_SQLitedriver, i.e. one PDO/SQLite connection, created in its constructor.
Impact
State that is connection-scoped in MySQL is shared across all proxy clients:
- Transactions:
BEGIN/COMMIT/ROLLBACKfrom one client commits or rolls back other clients' in-flight work on the shared connection. - Temporary tables: a
TEMPORARY TABLEcreated by one client is visible to (and droppable by) every other client. - Session state: user variables (
SET @x = ...),LAST_INSERT_ID(), and the current database (USE) are whatever the most recent client set them to. - Disconnect handling: one client disconnecting mid-transaction leaves the shared connection in that transaction state for the next client.
This is a correctness/isolation problem for the proxy's stated use case (serving non-PHP MySQL clients), rather than a cosmetic one: two ordinary, well-behaved clients can silently corrupt each other's work.
Why this is filed as an issue, not a PR
Fixing this requires one adapter/connection per session, which changes how MySQL_Proxy is constructed and used — a public API evolution that needs a maintainer decision (per the semver guidance in AGENTS.md). Plausible shapes:
- Adapter factory:
MySQL_Proxyaccepts a factory/callable that produces a freshAdapterper client session. The CLI (bin/wp-mysql-proxy.php) and the test server bootstrap would passfn() => new SQLite_Adapter( $db_path ). Backwards compatibility could be kept by still accepting a plainAdapter(documented as shared/single-client) or by a major-version change. - Cloneable adapter contract: an
Adapter::for_session()/clone-based method the proxy calls per session;SQLite_Adapterwould open a new driver connection per clone. Adapters that are inherently stateless could return$this.
Option 1 keeps the Adapter interface unchanged and makes the sharing explicit at the construction site, so it looks like the smaller, safer change — but I would like a maintainer's steer before implementing either.
Reproduction sketch
With the proxy running, open two concurrent client connections:
- Client A:
BEGIN; INSERT INTO t VALUES (1);(no commit) - Client B:
SELECT * FROM t;— sees A's uncommitted row;ROLLBACK;— rolls back A's transaction. - Client A:
COMMIT;— nothing left to commit; the row is gone.
Activity