Core dumped: Segmentation fault when using PDO with PDO::ATTR_EMULATE_PREPARES === false
Example:
$sql = "SELECT col1.table1, col2.table1, col1.table2 FROM table1 WHERE table2.id IN (?, ?) AND table1.available = 1 LIMIT ?" // missed JOIN is intended to replicate issue $params = array(1, 2, 3);
$mysql->setAttribute(\PDO::ATTR_EMULATE_PREPARES, false); $statement = $mysql->prepare($sql); $statement->execute($params); $query_result = $statement->fetchAll(\PDO::FETCH_ASSOC);
Dump: http://d.pr/f/t91q
Hi @flashek, do you have a stack trace (I don't see one in that dump) and a working self-contained repro? (I tried to run your example and it has syntax errors...) Thanks!
@scannell Yeah, sorry for syntax, code has been written ad-hoc without testing. Here's example, tested code + dump + stacktrace + sql dump:
code: http://d.pr/n/oQ7B dump: http://d.pr/n/2bdH stack: http://d.pr/n/mEs0 sql: http://d.pr/n/EVMi
@flashek, thanks. Could I trouble you to compile a debug build of HHVM and re-run and provide the same info? (Based on the lack of file and line info in the stacktrace I'm assuming this is a release build.)
@scannell I'm sorry but I don't have resources to do this outside my working place.
@flashek, without debug information this is unfortunately going to be difficult to diagnose. The mangled name of the exception (which is suspect and why I'd like to see this run on a debug build) on the stack trace looks like a connection error so perhaps you just can't access your MySQL database with the connection information you have? (If this only reproduces with PDO::ATTR_EMULATE_PREPARES set to false and/or with the error mode set to EXCEPTION I'd suggest changing one of those values in the meantime.)
@scannell I have tested various queries with and without PDO::ATTR_EMULATE_PREPARES and only "false" setting causes crash when try to SELECT columns which are not exists in table or have misspelled names. If I change value to "true" I got nice SQLSTATE error in hhvm log file. So I suppose that compiled error handling when PDO::ATTR_EMULATE_PREPARES is set to "false" is broken somehow.
I confirmed we default to using ATTR_EMULATE_PREPARES and we don't disable it in internal usage so it's highly possible there are bugs on the disabled path. Is this blocking you in your code or some third-party extension?
@scannell No, I have resigned from using ATTR_EMULATE_PREPARES so I'm fine. Regards.
@scannell - debug build results below:
maciek@Skiing-Yak:~/projects/hh-851$ /home/maciek/projects/hiphop-php/hphp/hhvm/hhvm test.php
hhvm: /home/maciek/projects/hiphop-php/hphp/runtime/ext/pdo_mysql.cpp:902: int HPHP::PDOMySqlStatement::handleError(const char*, int): Assertion `conn' failed.
Core dumped: Aborted
And stack trace:
Host: Skiing-Yak
ProcessID: 13671
ThreadID: 7f0925161200
ThreadPID: 13671
Name: /home/maciek/projects/hiphop-php/hphp/hhvm/hhvm
Type: Aborted
Runtime: hhvm
Version: heads/master-0-gbbcf1a2db3aa264ab2fb131f7ec414d49f35d0b8
DebuggerCount: 0
Arguments: test.php
ThreadType: CLI
# 0 bt_handler at /home/maciek/projects/hiphop-php/hphp/runtime/base/crash_reporter.cpp:58
# 1 killpg at /lib/x86_64-linux-gnu/libc.so.6:0
# 2 __GI_raise at /build/buildd/eglibc-2.15/signal/../nptl/sysdeps/unix/sysv/linux/raise.c:64
# 3 __GI_abort at /build/buildd/eglibc-2.15/stdlib/abort.c:93
# 4 __assert_fail_base at /build/buildd/eglibc-2.15/assert/assert.c:55
# 5 __assert_fail at /lib/x86_64-linux-gnu/libc.so.6:0
# 6 HPHP::PDOMySqlStatement::handleError(char const*, int) at /home/maciek/projects/hiphop-php/hphp/runtime/ext/pdo_mysql.cpp:903
# 7 HPHP::PDOMySqlStatement::create(HPHP::String const&, HPHP::Array const&) at /home/maciek/projects/hiphop-php/hphp/runtime/ext/pdo_mysql.cpp:874
# 8 HPHP::PDOMySqlConnection::preparer(HPHP::String const&, HPHP::SmartObject<HPHP::PDOStatement>*, HPHP::Variant const&) at /home/maciek/projects/hiphop-php/hphp/runtime/ext/pdo_mysql.cpp:477
# 9 HPHP::c_PDO::t_prepare(HPHP::String const&, HPHP::Array const&) at /home/maciek/projects/hiphop-php/hphp/runtime/ext/ext_pdo.cpp:1089
# 10 HPHP::tg_3PDO_prepare(HPHP::ActRec*) at /home/maciek/projects/hiphop-php/hphp/runtime/ext/ext_pdo.cpp.ext_hhvm.cpp:170
# 11 HPHP::VMExecutionContext::iopNativeImpl(unsigned char const*&) at /home/maciek/projects/hiphop-php/hphp/runtime/vm/bytecode.cpp:6535
# 12 void HPHP::VMExecutionContext::dispatchImpl<0>(int) at /home/maciek/projects/hiphop-php/hphp/runtime/vm/bytecode.cpp:7124
# 13 HPHP::VMExecutionContext::dispatch() at /home/maciek/projects/hiphop-php/hphp/runtime/vm/bytecode.cpp:7135
# 14 HPHP::VMExecutionContext::enterVMWork(HPHP::ActRec*) at /home/maciek/projects/hiphop-php/hphp/runtime/vm/bytecode.cpp:1550
# 15 HPHP::VMExecutionContext::enterVM(HPHP::TypedValue*, HPHP::ActRec*) at /home/maciek/projects/hiphop-php/hphp/runtime/vm/bytecode.cpp:1582
# 16 HPHP::VMExecutionContext::invokeFunc(HPHP::TypedValue*, HPHP::Func const*, HPHP::Array const&, HPHP::ObjectData*, HPHP::Class*, HPHP::VarEnv*, HPHP::StringData*, HPHP::VMExecutionContext::InvokeFlags) at /home/maciek/projects/hiphop-php/hphp/runtime/vm/bytecode.cpp:1800
# 17 HPHP::VMExecutionContext::invokeUnit(HPHP::TypedValue*, HPHP::Unit*) at /home/maciek/projects/hiphop-php/hphp/runtime/vm/bytecode.cpp:1903
# 18 HPHP::invoke_file_impl(HPHP::Variant&, HPHP::String const&, bool, char const*) at /home/maciek/projects/hiphop-php/hphp/runtime/base/builtin_functions.cpp:836
# 19 HPHP::invoke_file(HPHP::String const&, bool, char const*) at /home/maciek/projects/hiphop-php/hphp/runtime/base/builtin_functions.cpp:817
# 20 HPHP::include_impl_invoke(HPHP::String const&, bool, char const*) at /home/maciek/projects/hiphop-php/hphp/runtime/base/builtin_functions.cpp:811
# 21 HPHP::hphp_invoke(HPHP::ExecutionContext*, std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, bool, HPHP::Array const&, HPHP::VRefParamValue const&, std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, bool&, std::basic_string<char, std::char_traits<char>, std::allocator<char> >&, bool, bool, bool) at /home/maciek/projects/hiphop-php/hphp/runtime/base/program_functions.cpp:1459
# 22 HPHP::hphp_invoke_simple(std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, bool) at /home/maciek/projects/hiphop-php/hphp/runtime/base/program_functions.cpp:1430
# 23 execute_program_impl at /home/maciek/projects/hiphop-php/hphp/runtime/base/program_functions.cpp:1190
# 24 HPHP::execute_program(int, char**) at /home/maciek/projects/hiphop-php/hphp/runtime/base/program_functions.cpp:735
# 25 main at /home/maciek/projects/hiphop-php/hphp/hhvm/main.cpp:34
# 26 __libc_start_main at /build/buildd/eglibc-2.15/csu/libc-start.c:258
# 27 _start at /home/maciek/projects/hiphop-php/hphp/hhvm/hhvm:0
PHP Stacktrace:
#0 PDO->prepare(SELECT cr.id, cr.title, cr.image, cr.url, cr.campaign_id, cpg.event_type FROM creatives cr INNER JOIN campaigns cpg ON cr.campaign_id = cpg.id INNER JOIN categories ctg ON cr.id = ctg.creative_id INNER JOIN countries cnt ON cr.id = cnt.creative_id WHERE cr.id = ? GROUP BY cr.id LIMIT ?) called at [/home/maciek/projects/hh-851/test.php:17]
I would expect something along these lines:
maciek@Skiing-Yak:~/projects/hh-851$ /opt/php-5.5/bin/php test.php
Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE[42S02]: Base table or view not found: 1146 Table 'hh.campaigns' doesn't exist' in /home/maciek/projects/hh-851/test.php on line 17
PDOException: SQLSTATE[42S02]: Base table or view not found: 1146 Table 'hh.campaigns' doesn't exist in /home/maciek/projects/hh-851/test.php on line 17
Call Stack:
0.0004 253896 1. {main}() /home/maciek/projects/hh-851/test.php:0
0.0033 263160 2. PDO->prepare() /home/maciek/projects/hh-851/test.php:17
@iwankgb, thanks for producing this. This is definitely more actionable.