Skip to content

Conversation

Pequem
Copy link

@Pequem Pequem commented May 11, 2020

the PDO-firebird does not check if the connection is alive when persistent connections are used and that was generating the error:
SQLSTATE [HY000]: General error: -902 Error writing data to the connection.

@adambaratz
Copy link
Contributor

The code looks reasonable. Is there a way you could add a .phpt test that confirms the expected behavior? I realize testing on live connections is tricky, that this would be more of an integration test than a unit test, but we try to get this kind of coverage on the pdo extensions.

@Pequem
Copy link
Author

Pequem commented May 11, 2020

I based my code on the official firebird driver and tested it manually, sorry, but I don't know how to do unit testing.

https://github.com/FirebirdSQL/php-firebird/blob/master/interbase.c -> line 971

if ((le = zend_hash_str_find_ptr(&EG(persistent_list), hash, sizeof(hash)-1)) != NULL) {
if (le->type != le_plink) {
RETURN_FALSE;
}
/* check if connection has timed out */
ib_link = (ibase_db_link *) le->ptr;
if (!isc_database_info(status, &ib_link->handle, sizeof(info), info, sizeof(result), result)) {
RETVAL_RES(zend_register_resource(ib_link, le_plink));
break;
}
zend_hash_str_del(&EG(persistent_list), hash, sizeof(hash)-1);
}

@Pequem
Copy link
Author

Pequem commented May 11, 2020

My test was to create a loop that queries a table and then manually delete the connections from the MON$ATTACHMENTS table and see if it detected that the connection died

Edit: the loop calls an restAPI

@Pequem
Copy link
Author

Pequem commented May 12, 2020

I made a test file, it was really ugly but it worked :)

@diegosardina
Copy link

News on this PR?

@Pequem
Copy link
Author

Pequem commented Jul 30, 2021

News on this PR?

the solution works, runs on my server and solved the problem here.

@Girgias
Copy link
Member

Girgias commented Jan 4, 2023

Could you rebase this on latest master?

@Pequem
Copy link
Author

Pequem commented Jan 4, 2023

@Girgias
Hi, rebase done.

@Girgias
Copy link
Member

Girgias commented Jan 8, 2023

Windows fails with:

========DIFF========
001+ Fatal error: Uncaught PDOException: SQLSTATE[HY000]: General error in C:\projects\php-src\ext\pdo_firebird\tests\liveness.php:4
001- done
002+ Stack trace:
003+ #0 C:\projects\php-src\ext\pdo_firebird\tests\liveness.php(4): PDO->exec('DROP TABLE test...')
004+ #1 {main}
005+   thrown in C:\projects\php-src\ext\pdo_firebird\tests\liveness.php on line 4
========DONE========
FAIL PDO_Firebird: Check persistent conection is alive [C:\projects\php-src\ext\pdo_firebird\tests\liveness.phpt] 
=====================================================================
TIME END 2023-01-05 14:50:23

@cmb69 could you have a look?

@cmb69
Copy link
Member

cmb69 commented Jan 8, 2023

Windows fails with:

The basic problem is that the default error mode is PDO::ERRMODE_EXCEPTION as of PHP 8.0.0. Thus, silencing the attempt to delete the table is futile. An alternative would be

$dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_SILENT);
$dbh->exec('DROP TABLE testz');
$dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_WARNING);

Or, probably better (also as a step to be able to run these tests in parallel) use a unique table name according to the test name (i.e. liveness), and drop it in a --CLEAN-- section.

But why didn't that fail in the other CI runs? Because the pdo_firebird tests are skipped there:

<testsuite name="php.ext.pdo.firebird.tests" tests="112" failures="0" errors="0" skip="98" time="3.7339">

For instance, because of

<testcase name='ext/pdo_firebird/tests/bug_47415.phpt (Bug #47415 PDO_Firebird segfaults when passing lowercased column name to bindColumn())' time='0.0582'>
<skipped>: PDO_FIREBIRD_TEST_DSN must be set</skipped>
</testcase>

and

<testcase name='ext/pdo_firebird/tests/bug_34630.phpt (FIREBIRD PDO Common: Bug #34630 (inserting streams as LOBs))' time='0.1020'>
<skipped>SQLSTATE[HY000] [335544721] Unable to complete network request to host &quot;localhost&quot;.</skipped>
</testcase>

I suggest to fix CI before proceeding with this PR.

@github-actions
Copy link

There has not been any recent activity in this PR. It will automatically be closed in 7 days if no further action is taken.

@github-actions github-actions bot added the Stale label Apr 15, 2023
@github-actions github-actions bot closed this Apr 23, 2023
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.

6 participants