Skip to content

MYSQL_ATTR_INIT_COMMAND causing "The FastCGI process exited unexpectedly" #9381

Closed

Description

@HeavenCore

Description

We have some PHP code that has ran fine for years under PHP 7 / IIS / FastCGI

When updating to PHP 8.1.9 we're getting "The FastCGI process exited unexpectedly"

After digging through the code we have identified the issue as follows:

When using PDO::MYSQL_ATTR_INIT_COMMAND in the new PDO() constructor - FastCGI just dies

		$options = [
			PDO::ATTR_ERRMODE            => PDO::ERRMODE_EXCEPTION,
			PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC,
			PDO::ATTR_EMULATE_PREPARES   => false,
			PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES utf8mb4;"
		];

            $this->m_db = new PDO(
                $m_PDOConnectionString,
                $Username,
                $Password,
                $options
            );

Resulted in this output:

C:\Program Files (x86)\PHP\v8.1.9.dev\php-cgi.exe - The FastCGI process exited unexpectedly

But I expected this output instead:

N/A - expected DB connection to open as normal

Only thing i can find in the windows event log is as follows:

Faulting application name: php-cgi.exe, version: 8.1.9.0, time stamp: 0x62e93213
Faulting module name: php8.dll, version: 8.1.9.0, time stamp: 0x62e93aac
Exception code: 0xc0000005
Fault offset: 0x00008fac
Faulting process id: 0x4d4
Faulting application start time: 0x01d8b3db35c39991
Faulting application path: C:\Program Files (x86)\PHP\v8.1.9.dev\php-cgi.exe
Faulting module path: C:\Program Files (x86)\PHP\v8.1.9.dev\php8.dll
Report Id: 3737167c-6b9f-48b2-bdfb-74baff4570ec
Faulting package full name: 
Faulting package-relative application ID: 

Removing MYSQL_ATTR_INIT_COMMAND solves the prooblem and everything starts working again.

The systax we're using here, i.e. "SET NAMES utf8mb4;" is a valid MySQL command which we've tested in mySQL workbench etc

Is this related to #9143 i wonder?

PHP Version

8.1.9

Operating System

Windows Server 2019

Activity

  1. cmb69 commented on Aug 19, 2022

    @cmb69
    Member

    I cannot reproduce this segfault. Could you please try to generate a stack backtrace?

  2. HeavenCore commented on Aug 23, 2022

    @HeavenCore
    Author

    Good Morning,

    Backtrace below as requested:

    Error

    In php-cgi.exe_220823_081756.dmp the assembly instruction at php8!emalloc+5c in C:\Program Files (x86)\PHP\v8.1.9.dev\php8.dll from The PHP Group has caused an access violation exception (0xC0000005) when trying to read from memory location 0x0f003b34 on thread 0

    Faulting Thread

    Entry Point: php_cgi!mainCRTStartup

    php8!emalloc+5c [D:\a\php-ftw\php-ftw\php\vs16\x86\php-8.1.9\Zend\zend_alloc.c @ 2541 + 45]    0000009    fba90c0    0000000    f300014  D:\a\php-ftw\php-ftw\php\vs16\x86\php-8.1.9\Zend\zend_alloc.c @ 2541 + 45
    php8!_mysqlnd_pestrndup+58 [D:\a\php-ftw\php-ftw\php\vs16\x86\php-8.1.9\ext\mysqlnd\mysqlnd_alloc.c @ 306]    f353080    0000009    0000000    f300014  D:\a\php-ftw\php-ftw\php\vs16\x86\php-8.1.9\ext\mysqlnd\mysqlnd_alloc.c @ 306
    php8!mysqlnd_set_persistent_string+52 [D:\a\php-ftw\php-ftw\php\vs16\x86\php-8.1.9\ext\mysqlnd\mysqlnd_alloc.h @ 93 + 2]    f300014    f353080    0000009    0000000  D:\a\php-ftw\php-ftw\php\vs16\x86\php-8.1.9\ext\mysqlnd\mysqlnd_alloc.h @ 93 + 2
    php8!mysqlnd_mysqlnd_conn_data_connect_pub+553 [D:\a\php-ftw\php-ftw\php\vs16\x86\php-8.1.9\ext\mysqlnd\mysqlnd_connection.c @ 677]    f300008    f353080    0000009    f353070  D:\a\php-ftw\php-ftw\php\vs16\x86\php-8.1.9\ext\mysqlnd\mysqlnd_connection.c @ 677
    php8!mysqlnd_mysqlnd_conn_connect_pub+a2 [D:\a\php-ftw\php-ftw\php\vs16\x86\php-8.1.9\ext\mysqlnd\mysqlnd_connection.c @ 768 + 2]    f2ac9f8    f353080    0000009    f353070  D:\a\php-ftw\php-ftw\php\vs16\x86\php-8.1.9\ext\mysqlnd\mysqlnd_connection.c @ 768 + 2
    php8!mysqlnd_connection_connect+131 [D:\a\php-ftw\php-ftw\php\vs16\x86\php-8.1.9\ext\mysqlnd\mysqlnd_connection.c @ 2325 + 2]    f2ac9f8    f353080    f353070    f2adaf0  D:\a\php-ftw\php-ftw\php\vs16\x86\php-8.1.9\ext\mysqlnd\mysqlnd_connection.c @ 2325 + 2
    php_pdo_mysql!pdo_mysql_handle_factory+8c5 [D:\a\php-ftw\php-ftw\php\vs16\x86\php-8.1.9\ext\pdo_mysql\mysql_driver.c @ 937 + 24]    f2b0a00    f215f30    0000000    fd07b90  D:\a\php-ftw\php-ftw\php\vs16\x86\php-8.1.9\ext\pdo_mysql\mysql_driver.c @ 937 + 24
    php8!zim_PDO___construct+62d [D:\a\php-ftw\php-ftw\php\vs16\x86\php-8.1.9\ext\pdo\pdo_dbh.c @ 386 + 2]    f31578c    faf5ff0    f3ad1d0    f215c00  D:\a\php-ftw\php-ftw\php\vs16\x86\php-8.1.9\ext\pdo\pdo_dbh.c @ 386 + 2
    php8!ZEND_DO_FCALL_SPEC_RETVAL_UNUSED_HANDLER+64 [D:\a\php-ftw\php-ftw\php\vs16\x86\php-8.1.9\Zend\zend_vm_execute.h @ 1779]    f214010    faf73d0    0000000    0000000  D:\a\php-ftw\php-ftw\php\vs16\x86\php-8.1.9\Zend\zend_vm_execute.h @ 1779
    php8!execute_ex+96 [D:\a\php-ftw\php-ftw\php\vs16\x86\php-8.1.9\Zend\zend_vm_execute.h @ 55562 + 4]    f214010    f26b240    f2790a0    6c2c160  D:\a\php-ftw\php-ftw\php\vs16\x86\php-8.1.9\Zend\zend_vm_execute.h @ 55562 + 4
    php8!zend_execute+11d [D:\a\php-ftw\php-ftw\php\vs16\x86\php-8.1.9\Zend\zend_vm_execute.h @ 60125]    f2790a0    0000000    0000000    0000000  D:\a\php-ftw\php-ftw\php\vs16\x86\php-8.1.9\Zend\zend_vm_execute.h @ 60125
    php8!zend_execute_scripts+157 [D:\a\php-ftw\php-ftw\php\vs16\x86\php-8.1.9\Zend\zend.c @ 1790 + 9]    0000008    0000000    0000003    0000000  D:\a\php-ftw\php-ftw\php\vs16\x86\php-8.1.9\Zend\zend.c @ 1790 + 9
    php8!php_execute_script+238 [D:\a\php-ftw\php-ftw\php\vs16\x86\php-8.1.9\main\main.c @ 2539 + f]    6c2eb20    08d34c0    08cd828    06c9000  D:\a\php-ftw\php-ftw\php\vs16\x86\php-8.1.9\main\main.c @ 2539 + f
    php_cgi!main+12e5 [D:\a\php-ftw\php-ftw\php\vs16\x86\php-8.1.9\sapi\cgi\cgi_main.c @ 2525 + a]    0000001    08cd828    08d34c0    3445a40  D:\a\php-ftw\php-ftw\php\vs16\x86\php-8.1.9\sapi\cgi\cgi_main.c @ 2525 + a
    php_cgi!__scrt_common_main_seh+fa [D:\a\_work\1\s\src\vctools\crt\vcstartup\src\startup\exe_common.inl @ 288 + 1c]    06c9000    7990400    6c2fd78    7bc77fd  D:\a\_work\1\s\src\vctools\crt\vcstartup\src\startup\exe_common.inl @ 288 + 1c
    kernel32!BaseThreadInitThunk+19    06c9000    d18ad98    0000000    0000000  
    ntdll!RtlGetAppContainerNamedObjectPath+ed    fffffff    7be714b    0000000    0000000  
    ntdll!RtlGetAppContainerNamedObjectPath+bd    0c12cb0    06c9000    0000000    0000000  
  3. HeavenCore commented on Aug 23, 2022

    @HeavenCore
    Author

    Above trace was produced by un-commenting the following:

    PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES utf8mb4;"

    in the following code block:

    $options = [
    	PDO::ATTR_ERRMODE            => PDO::ERRMODE_EXCEPTION,
    	PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC,
    	PDO::ATTR_EMULATE_PREPARES   => false,
    	//PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES utf8mb4;"
    ];
    
    $this->m_db = new PDO(
    	$m_PDOConnectionString,
    	$Username,
    	$Password,
    	$options
    );
    

    WIth this line commented out the application compiles and runs normally.

  4. cmb69 commented on Aug 23, 2022

    @cmb69
    Member

    Thank you for the backtrace! This is likely not the root cause, but may just be a cause of a prior memory mismanagement. I'm not able to find anything, though, especially something related to the MYSQL_ATTR_INIT_COMMAND.

    At least the backtrace shows that this happens with a 32bit build; can you also reproduce the issue with a 64bit build?

  5. HeavenCore commented on Aug 23, 2022

    @HeavenCore
    Author

    wow, that's very interesting - i've been unable to recreate the issue in x64 - so yep, appears to be an x86 issue only :)

    I'll advise the customer to use x64 going forward.

    I suspect you're correct, perhaps it's not reserving enough memory for the PDO option array or something, i.e. it's the number of options in the array as opposed to the array items themselves? That's outside my area of expertise though - looking forward to hearing from a clever person as to what the actual issue is in x86.

    OffTopic: is there any plans to kill x86 PHP?

  6. cmb69 commented on Aug 24, 2022

    @cmb69
    Member

    I'll advise the customer to use x64 going forward.

    That is generally a good idea (as of PHP 7.0.0 on Windows). :)

    OffTopic: is there any plans to kill x86 PHP?

    It has been suggested a few times, but probably that won't happen soon (one argument is support for embedded devices etc.)

  7. hormus commented on Sep 5, 2022

    @hormus
  8. HeavenCore commented on Sep 5, 2022

    @HeavenCore
    Author
  9. hormus commented on Sep 5, 2022

    @hormus
  10. kamil-tekiela commented on Nov 5, 2026

    @kamil-tekiela
    Member

    This was a heap overflow in mysqlnd on 32-bit builds with mysqlnd.collect_memory_statistics=On, fixed in PHP 8.1.13 by #9724. If that's not the case, and you still experience this issue with the recent PHP version, please open a new GH issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions