php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #63176 Segmentation fault when instantiate 2 persistent PDO to the same db server
Submitted: 2012-09-28 02:10 UTC Modified: 2013-06-16 15:02 UTC
Votes:5
Avg. Score:4.6 ± 0.5
Reproduced:5 of 5 (100.0%)
Same Version:3 (60.0%)
Same OS:4 (80.0%)
From: jrbasso at gmail dot com Assigned: wez (profile)
Status: Closed Package: PDO related
PHP Version: 5.4.7 OS: Ubunt 12.04.1
Private report: No CVE-ID: None
 [2012-09-28 02:10 UTC] jrbasso at gmail dot com
Description:
------------
Download the PHP version 5.4.7, compiled with ./configure --enable-debug --with-
pdo-mysql --enable-pcntl

Run the test script and it gives a segmentation fault when the script finish. If 
I remove the attribute from PDO2 it works fine. If the persistent option is 
disabled it works fine too.

gdb backtrace available on https://gist.github.com/3bda9d5253e7a86168e0


Test script:
---------------
<?php

class PDO2 extends PDO {
	protected $transLevel;
}

class ModelA {
	public function __construct() {
		$this->db = new PDO2('mysql:host=localhost', 'root', 'root', array(PDO::ATTR_PERSISTENT => true));
		$this->db->query('SELECT 1')->fetchAll();
	}
}

$a = new ModelA();
$b = new ModelA();


Expected result:
----------------
No segmentation fault

Actual result:
--------------
Segmentation fault (core dumped)

Patches

bug63176.patch (last revision 2012-09-28 02:47 UTC by laruence@php.net)

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2012-09-28 02:47 UTC] laruence@php.net
The following patch has been added/updated:

Patch Name: bug63176.patch
Revision:   1348800472
URL:        https://bugs.php.net/patch-display.php?bug=63176&patch=bug63176.patch&revision=1348800472
 [2012-09-28 02:55 UTC] laruence@php.net
@wez, could you please look at this? the attached patch indicated where the 
problem came from. :)

thanks
 [2012-09-28 02:55 UTC] laruence@php.net
-Assigned To: +Assigned To: wez
 [2012-09-28 13:22 UTC] cjsaylor at gmail dot com
After looking at the patch, is denying persistent connections from derived PDO 
classes the actual proposed solution?  Not being able to extend \PDO with 
persistent connections would be a problem in many frameworks/appliances.
 [2012-09-28 13:37 UTC] jrbasso at gmail dot com
I tested in my PHP 5.3.15 and the issue doesn't happen. It just happen in PHP 
5.4.x.
 [2013-06-14 13:16 UTC] thz at plista dot com
Hi, we are experiencing the same error and it's preventing us from moving to PHP 
5.4. Are there any plans to fix this or are we going to have to live with not 
being able to derive from PDO?

We have done extensive debugging and may be able to provide some information as 
to why this happens, but due to a lack of internal knowledge of how the Zend 
engine works, we haven't been able to come up with a fix.
 [2013-06-14 19:31 UTC] jrbasso at gmail dot com
@thz, the workaround I did was to create 2 DNS names for the same DB. So PHP will 
think they are 2 different servers and connect twice.
 [2013-06-16 14:57 UTC] laruence@php.net
Automatic comment on behalf of laruence
Revision: http://git.php.net/?p=php-src.git;a=commit;h=49e57a31659a82443b9413127f8d58a72f09ed5b
Log: Fixed bug #63176 (Segmentation fault when instantiate 2 persistent PDO to the same db server)
 [2013-06-16 14:57 UTC] laruence@php.net
-Status: Assigned +Status: Closed
 [2013-06-16 15:01 UTC] laruence@php.net
bug has been fixed, will behavior like 5.3

but it's a little weird that's two different drived class will share one same dbh, 
and the dbh hold only one drived  class instance.

see the test script I committed: https://github.com/php/php-
src/blob/6cd6349ff8842a9356723b7b192eb3c93fb64c7e/ext/pdo_mysql/tests/bug63176.php
t

note the result are all PDO2.... 

maybe we should also add the drived class name into the persistent id? 

thanks
 [2013-06-16 15:02 UTC] laruence@php.net
@wez what do you think? thanks
 [2013-06-17 08:38 UTC] tj dot botha at plista dot com
Hey guys - thanks very much for fixing this! I pulled 
1143f58a7094ed9a4960bfb714fa2773dda7c704 this morning and confirm we're also no 
longer segfaulting.

:)
 [2014-10-07 23:18 UTC] stas@php.net
Automatic comment on behalf of laruence
Revision: http://git.php.net/?p=php-src-security.git;a=commit;h=49e57a31659a82443b9413127f8d58a72f09ed5b
Log: Fixed bug #63176 (Segmentation fault when instantiate 2 persistent PDO to the same db server)
 [2014-10-07 23:30 UTC] stas@php.net
Automatic comment on behalf of laruence
Revision: http://git.php.net/?p=php-src-security.git;a=commit;h=49e57a31659a82443b9413127f8d58a72f09ed5b
Log: Fixed bug #63176 (Segmentation fault when instantiate 2 persistent PDO to the same db server)
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Mon Dec 30 14:01:28 2024 UTC