Skip to content

feat(mysqlnd): send COM_RESET_CONNECTION in restart_psession#21857

Open
ericnorris wants to merge 1 commit intophp:masterfrom
ericnorris:feat-mysqlnd-com-reset-connection
Open

feat(mysqlnd): send COM_RESET_CONNECTION in restart_psession#21857
ericnorris wants to merge 1 commit intophp:masterfrom
ericnorris:feat-mysqlnd-com-reset-connection

Conversation

@ericnorris
Copy link
Copy Markdown
Contributor

Closes #20225. I'm not sure if adding this to PDO is a step too far; we could limit this to just mysqlnd if necessary.

Disclosure: I've used Claude to write the commit (the commit message is mostly mine), but take full responsibility for the changes and have reviewed it to the best of my ability.


Before this commit, persistent MySQL connection reuse relied on COM_CHANGE_USER to reset server-side session state in mysqli. PDO MySQL did not reset server-side state at all, it only pinged to check liveness, leaving user variables, temporary tables, and transaction state from previous requests intact.

After this commit, both mysqli and PDO MySQL send COM_RESET_CONNECTION when reusing a persistent connection, which resets all server-side session state without re-authentication.

We've implemented this by adding a reset_connection command to mysqlnd's command layer. It's similar to the existing ping command, since there's no payload. We now call it from restart_psession, which we've also changed to return enum_func_status so callers can handle failures.

In mysqli, we've replaced the COM_CHANGE_USER call in the persistent reuse path with a call to restart_psession.

In PDO MySQL, we've replaced the mysql_ping in check_liveness with a call to restart_psession, which both verifies the connection is alive and resets session state in a single round trip. We've also removed a call to restart_psession on unconnected handles during initialization.

Before this commit, persistent MySQL connection reuse relied on
COM_CHANGE_USER to reset server-side session state in mysqli. PDO MySQL
did not reset server-side state at all; it only pinged to check
liveness, leaving user variables, temporary tables, and transaction
state from previous requests intact.

After this commit, both mysqli and PDO MySQL send COM_RESET_CONNECTION
when reusing a persistent connection, which resets all server-side
session state without re-authentication.

We've implemented this by adding a reset_connection command to mysqlnd's
command layer. It's similar to the existing ping command, since there's
no payload. We now call it from restart_psession, which we've also
changed to return enum_func_status so callers can handle failures.

In mysqli, we've replaced the COM_CHANGE_USER call in the persistent
reuse path with a call to restart_psession.

In PDO MySQL, we've replaced the mysql_ping in check_liveness with a
call to restart_psession, which both verifies the connection is alive
and resets session state in a single round trip. We've also removed a
call to restart_psession on unconnected handles during initialization.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Send COM_RESET_CONNECTION in mysqlnd_conn_data::restart_psession

1 participant