Skip to content

pdo_dblib: Do not reuse dead connections#21681

Open
freddy77 wants to merge 1 commit intophp:masterfrom
freddy77:master
Open

pdo_dblib: Do not reuse dead connections#21681
freddy77 wants to merge 1 commit intophp:masterfrom
freddy77:master

Conversation

@freddy77
Copy link
Copy Markdown

@freddy77 freddy77 commented Apr 9, 2026

In case of persistent connection it was not checked if the connection was still alive always assuming it was. If the connection was broken this caused PHP to reuse the broken connection over and over.
dbdead function is supported by all dblib implementation (MS, Sybase, FreeTDS).
Change tested manually, see FreeTDS/freetds#711 (comment)

Feel free to update comment or code.
As the comment above I didn't test the change myself.
I don't see an easy way to write a test for this change.

In case of persistent connection it was not checked if the
connection was still alive always assuming it was.
If the connection was broken this caused PHP to reuse the
broken connection over and over.
dbdead function is supported by all dblib implementation
(MS, Sybase, FreeTDS).
Change tested manually, see
FreeTDS/freetds#711 (comment)

Signed-off-by: Frediano Ziglio <freddy77@gmail.com>
Copy link
Copy Markdown
Member

@SakiTakamachi SakiTakamachi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry for the delayed review.
This makes a lot of sense.

Regarding tests, I’ve done something similar in pdo_firebird before. In that case, I wrote a test to ensure that check_liveness is not broken and that the same connection is reused when using persistent connections.

https://github.com/php/php-src/blob/master/ext/pdo_firebird/tests/persistent_connect.phpt

For SQL Server or Sybase, you can obtain the connection ID with SELECT @@SPID, so it should be possible to create a test similar to the one for Firebird.

If this would be a burden for you, I can also add the test myself.

Anyway, thank you for this change!

Comment on lines +429 to +430
if (dbdead(H->link))
return FAILURE;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nits:
https://github.com/php/php-src/blob/master/CODING_STANDARDS.md#syntax-and-indentation

Suggested change
if (dbdead(H->link))
return FAILURE;
if (dbdead(H->link)) {
return FAILURE;
}

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.

2 participants