Skip to content

fix(mysql): add lock_wait_timeout to DSN to stop statement pile-up - #423

Open
jabbrwcky wants to merge 3 commits into
crossplane-contrib:masterfrom
jabbrwcky:fix/mysql-lock-wait-timeout
Open

fix(mysql): add lock_wait_timeout to DSN to stop statement pile-up#423
jabbrwcky wants to merge 3 commits into
crossplane-contrib:masterfrom
jabbrwcky:fix/mysql-lock-wait-timeout

Conversation

@jabbrwcky

@jabbrwcky jabbrwcky commented Jul 22, 2026

Copy link
Copy Markdown
Contributor

Description of your changes

Under a backlog of pending ALTER USER/GRANT/DDL statements, MySQL/Percona can become unresponsive. go-sql-driver/mysql cancels a context by closing the TCP socket without sending KILL QUERY (intentional; all versions incl. latest v1.10.0). With MySQL's default lock_wait_timeout of 1 year, a statement blocked on a metadata/ACL lock (e.g. behind a backup or long transaction) stays pending server-side even after the 60s reconcile deadline. Every retry adds another; account-management statements serialize on a single global ACL lock, so they pile up until max_connections is exhausted or the server wedges.

This PR appends lock_wait_timeout=30 and dial timeout=10s to the MySQL DSN so blocked statements fail fast server-side and release instead of accumulating. Applies to all MySQL controllers (User, Grant, Database; cluster + namespaced) via the shared client.

Not covered / follow-ups:

See docs/mysql-driver-context-cancellation.md for the full analysis.

Fixes #422

I have:

  • Read and followed Crossplane's contribution process.
  • Run make reviewable to ensure this PR is ready for review.

How has this code been tested

  • Updated DSN assertions; added TestDSNParsesWithLockWaitTimeout validating the DSN parses via the driver and carries the params.
  • go build ./..., go vet, and full MySQL controller test suites pass.
  • make and make reviewable pass.

@jabbrwcky
jabbrwcky force-pushed the fix/mysql-lock-wait-timeout branch from 3a907a7 to d44b68f Compare July 22, 2026 08:13
jabbrwcky and others added 3 commits July 23, 2026 14:55
MySQL/Percona could become unresponsive under a growing backlog of
pending ALTER USER (and other) statements issued by provider-sql.

Root cause: go-sql-driver/mysql cancels a context by closing the TCP
socket without sending KILL QUERY (intentional, all versions incl. the
latest v1.10.0). With MySQL's default lock_wait_timeout of 1 year, a
statement blocked on a metadata/ACL lock (e.g. behind a backup or long
transaction) stays pending server-side even after the 60s reconcile
deadline makes the provider give up. Every reconcile retry issues
another blocked statement; account-management statements additionally
serialize on a single global ACL lock, so they pile up until
max_connections is exhausted or ACL contention wedges the server.

Append lock_wait_timeout=30 and a dial timeout=10s to the MySQL DSN so
blocked statements fail fast server-side and release instead of
accumulating. This covers every MySQL controller (User, Grant,
Database; cluster and namespaced) since they share this client.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Signed-off-by: Jens Hausherr <jens.hausherr@pflege.de>
Records why go-sql-driver/mysql cancelling a context by closing the
socket (rather than issuing KILL QUERY) matters operationally, the full
incident chain it can cause, the lock_wait_timeout mitigation, what it
does not cover, and follow-up ideas.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Signed-off-by: Jens Hausherr <jens.hausherr@pflege.de>
Signed-off-by: Jens Hausherr <jens.hausherr@pflege.de>
@jabbrwcky
jabbrwcky force-pushed the fix/mysql-lock-wait-timeout branch from a3c8bc3 to b067c97 Compare July 23, 2026 12:58
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.

MySQL: pending ALTER USER/GRANT statements pile up and make the server unresponsive

1 participant