php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #64647 Segfault in eio_fstat
Submitted: 2013-04-14 02:16 UTC Modified: 2013-07-24 18:46 UTC
Votes:1
Avg. Score:1.0 ± 0.0
Reproduced:0 of 1 (0.0%)
From: imprec at gmail dot com Assigned: osmanov (profile)
Status: Closed Package: eio (PECL)
PHP Version: 5.4.6 OS: Ubuntu
Private report: No CVE-ID: None
 [2013-04-14 02:16 UTC] imprec at gmail dot com
Description:
------------
When running example code from eio_open documentation, I sometimes encounter a 
segmentation fault

System : Ubuntu server

PHP 5.4.6-1ubuntu1.2 (cli) (built: Mar 11 2013 14:57:54) 
Copyright (c) 1997-2012 The PHP Group
Zend Engine v2.4.0, Copyright (c) 1998-2012 Zend Technologies


romain@ubuntu:~$ php --ri eio

eio

eio support => enabled
Debug support => disabled
Version => 1.2.1


Here are two gdb dumps : 

GNU gdb (GDB) 7.5-ubuntu
Copyright (C) 2012 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.  Type "show copying"
and "show warranty" for details.
This GDB was configured as "x86_64-linux-gnu".
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>...
Reading symbols from /usr/bin/php...Reading symbols from 
/usr/lib/debug/usr/bin/php5...done.
done.
(gdb) (gdb) Starting program: /usr/bin/php eio.php
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib/x86_64-linux-gnu/libthread_db.so.1".
[New Thread 0x7ffff7e58700 (LWP 15599)]
string(4) "open"
array(13) {
  ["dev"]=>
  int(64512)
  ["ino"]=>
  int(35081)
  ["mode"]=>
  int(33188)
  ["nlink"]=>
  int(1)
  ["uid"]=>
  int(0)
  ["size"]=>
  int(0)
  ["gid"]=>
  int(0)
  ["rdev"]=>
  int(0)
  ["blksize"]=>
  int(4096)
  ["blocks"]=>
  int(0)
  ["atime"]=>
  int(1365905382)
  ["mtime"]=>
  int(1365905382)
  ["ctime"]=>
  int(1365905382)
}

Program received signal SIGSEGV, Segmentation fault.
[Switching to Thread 0x7ffff7e58700 (LWP 15599)]
0x00007ffff54ffd98 in pthread_cond_wait@@GLIBC_2.3.2 () from /lib/x86_64-linux-
gnu/libpthread.so.0
(gdb) #0  0x00007ffff54ffd98 in pthread_cond_wait@@GLIBC_2.3.2 () from 
/lib/x86_64-linux-gnu/libpthread.so.0
No symbol table info available.
#1  0x00007ffff4d19c39 in ?? ()
No symbol table info available.
#2  0x0000000000000000 in ?? ()
No symbol table info available.


And :


GNU gdb (GDB) 7.5-ubuntu
Copyright (C) 2012 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.  Type "show copying"
and "show warranty" for details.
This GDB was configured as "x86_64-linux-gnu".
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>...
Reading symbols from /usr/bin/php...Reading symbols from 
/usr/lib/debug/usr/bin/php5...done.
done.
(gdb) (gdb) Starting program: /usr/bin/php eio.php
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib/x86_64-linux-gnu/libthread_db.so.1".
[New Thread 0x7ffff7e58700 (LWP 15663)]
string(4) "open"
array(13) {
  ["dev"]=>
  int(64512)
  ["ino"]=>
  int(35081)
  ["mode"]=>
  int(33188)
  ["nlink"]=>
  int(1)
  ["uid"]=>
  int(0)
  ["size"]=>
  int(0)
  ["gid"]=>
  int(0)
  ["rdev"]=>
  int(0)
  ["blksize"]=>
  int(4096)
  ["blocks"]=>
  int(0)
  ["atime"]=>
  int(1365905444)
  ["mtime"]=>
  int(1365905444)
  ["ctime"]=>
  int(1365905444)
}

Program received signal SIGSEGV, Segmentation fault.
[Switching to Thread 0x7ffff7e58700 (LWP 15663)]
0x00007ffff4d19d34 in ?? ()
(gdb) #0  0x00007ffff4d19d34 in ?? ()
No symbol table info available.
#1  0x0000000000000000 in ?? ()
No symbol table info available.



Test script:
---------------
/ Create temporary file
$tmp_filename = dirname(__FILE__) ."/eio-file.tmp";
touch($tmp_filename);

/* Is called when eio_fstat() done */
function my_res_cb($data, $result) {
 // Should output array with stat info
 var_dump($result);

 if ($data['fd']) {
  // Close temporary file
  eio_close($data['fd']);
  eio_event_loop();
 }
 // Remove temporary file
 @unlink($data['file']);
}

/* Is called when eio_open() done */
function my_open_cb($data, $result) {
    var_dump('open');
 // Prepare data for callback
 $d = array(
  'fd'  => $result,
  'file'=> $data
 );
 // Request stat info
 eio_fstat($result, EIO_PRI_DEFAULT, "my_res_cb", $d);
 // Process request(s)
 eio_event_loop();
}

// Open temporary file
eio_open($tmp_filename, EIO_O_RDONLY, NULL, EIO_PRI_DEFAULT,
  "my_open_cb", $tmp_filename);
eio_event_loop();




Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2013-04-14 02:17 UTC] imprec at gmail dot com
Update OS
 [2013-04-14 02:17 UTC] imprec at gmail dot com
-Operating System: OSX +Operating System: Ubuntu -PHP Version: Irrelevant +PHP Version: 5.4.6
 [2013-04-14 12:11 UTC] osmanov@php.net
-Status: Open +Status: Feedback
 [2013-04-14 12:11 UTC] osmanov@php.net
Thank you for this bug report. To properly diagnose the problem, we
need a backtrace to see what is happening behind the scenes. To
find out how to generate a backtrace, please read
http://bugs.php.net/bugs-generating-backtrace.php for *NIX and
http://bugs.php.net/bugs-generating-backtrace-win32.php for Win32

Once you have generated a backtrace, please submit it to this bug
report and change the status back to "Open". Thank you for helping
us make PHP better.

You've reported another bug here: https://bugs.php.net/bug.php?id=64648
Did you run the test script with php-uv extension loaded? In this case my answer is still the same: php-uv conflicts with eio.

If the bug is reproduced without php-uv, I need a gdb backtrace. However, eio should be compiled with --enable-eio-debug flag.
 [2013-04-14 15:29 UTC] imprec at gmail dot com
-Status: Feedback +Status: Open
 [2013-04-14 15:29 UTC] imprec at gmail dot com
Hello,

thanks for your quick answer !

The segfault occurs without php-uv. It does not happen all the time with the 
script I provided. Let's say it happens 30% of the time.

Here is another backtrace I just got :

Program received signal SIGSEGV, Segmentation fault.
[Switching to Thread 0x7ffff7e58700 (LWP 874)]
0x00007ffff54ffd98 in pthread_cond_wait@@GLIBC_2.3.2 () from /lib/x86_64-linux-
gnu/libpthread.so.0
(gdb) #0  0x00007ffff54ffd98 in pthread_cond_wait@@GLIBC_2.3.2 () from 
/lib/x86_64-linux-gnu/libpthread.so.0
No symbol table info available.
#1  0x00007ffff4d19650 in ?? ()
No symbol table info available.
#2  0x00007ffff7e58700 in ?? ()
No symbol table info available.
#3  0x0000000001014c60 in ?? ()
No symbol table info available.
#4  0x0000000001014c60 in ?? ()
No symbol table info available.
#5  0x0000000000000000 in ?? ()
No symbol table info available.

php : 


romain@ubuntu:~$ php -v
PHP 5.4.6-1ubuntu1.2 (cli) (built: Mar 11 2013 14:57:54) 
Copyright (c) 1997-2012 The PHP Group
Zend Engine v2.4.0, Copyright (c) 1998-2012 Zend Technologies

romain@ubuntu:~$ php -m
[PHP Modules]
bcmath
bz2
calendar
Core
ctype
date
dba
dom
eio
ereg
exif
fileinfo
filter
ftp
gettext
hash
iconv
json
libevent
libxml
mbstring
mhash
openssl
pcntl
pcre
PDO
Phar
posix
readline
Reflection
session
shmop
SimpleXML
soap
sockets
SPL
standard
sysvmsg
sysvsem
sysvshm
tokenizer
wddx
xml
xmlreader
xmlwriter
zip
zlib

[Zend Modules]


romain@ubuntu:~$ php --ri eio

eio

eio support => enabled
Debug support => enabled
Version => 1.2.1



Unfortunately PHP debug symbols does not work well on ubuntu (I've installed 
php5-dbg which is supposed to provide the debug mode)
I've tried to recompile PHP 5.4.14 from scratch with the following configure 
options ;

./configure --enable-debug --with-tsrm-pthreads

But once I install php-eio I got the following error : 

romain@ubuntu:~$ php -v
php: symbol lookup error: /usr/local/lib/php/extensions/debug-non-zts-
20100525/eio.so: undefined symbol: pthread_atfork


I would be glad to help you, but I'm stuck here
 [2013-04-14 18:47 UTC] osmanov@php.net
Indeed, it's hard to get the proper debug symbols with Ubuntu's packages.

Not sure what you meant by --with-tsrm-pthreads. But, AFAIK, pthreads extension
requires ZTS, i.e. --enable-maintainer-zts. I suspect the bug is somehow
concerned with pthreads, isn't it? ;) In case you're using such a "nuclear"
couple as eio + pthreads, ... I wouldn't recommend it.

Are you using libevent extension in conjuction with eio? If so, I'd strongly
recommend to replace it with "event" extension. I don't blame libevent extension
in some kind of incorrect behaviour. I just recommend newer OOP API provided by
the Event extension which supports the latest version of libevent(in contrast
with "libevent" ext.)

Do you get the segfault running exactly the test script provided here?
 [2013-04-14 19:19 UTC] imprec at gmail dot com
Re,

no, I'm not using pthreads... I supposed it's used by eio. Actually, as I got a 
pthread error when loading the library I found this option in ./configure --help 
of PHP.

I've rebuilt a PHP 5.4.14 from scratch with :

romain@ubuntu:~/php-5.4.14$ php -i|grep configure
Configure Command =>  './configure'  '--enable-debug' '--enable-maintainer-zts'

romain@ubuntu:~/php-5.4.14$ php -v
PHP 5.4.14 (cli) (built: Apr 14 2013 19:38:49) (DEBUG)
Copyright (c) 1997-2013 The PHP Group
Zend Engine v2.4.0, Copyright (c) 1998-2013 Zend Technologies

romain@ubuntu:~/php-5.4.14$ php -m
[PHP Modules]
Core
ctype
date
dom
eio
ereg
fileinfo
filter
hash
iconv
json
libxml
pcre
PDO
pdo_sqlite
Phar
posix
Reflection
session
SimpleXML
SPL
sqlite3
standard
tokenizer
xml
xmlreader
xmlwriter

[Zend Modules]

romain@ubuntu:~/php-5.4.14$ php --ri eio

eio

eio support => enabled
Debug support => enabled
Version => 1.2.1



Yes I run the script I provided (that is a direct copy/paste of PHP eio doc) :


// Create temporary file
$tmp_filename = dirname(__FILE__) ."/eio-file.tmp";
touch($tmp_filename);

/* Is called when eio_fstat() done */
function my_res_cb($data, $result) {
 // Should output array with stat info
 var_dump($result);

 if ($data['fd']) {
  // Close temporary file
  eio_close($data['fd']);
  eio_event_loop();
 }
 // Remove temporary file
 @unlink($data['file']);
}

/* Is called when eio_open() done */
function my_open_cb($data, $result) {
    var_dump('open');
 // Prepare data for callback
 $d = array(
  'fd'  => $result,
  'file'=> $data
 );
 // Request stat info
 eio_fstat($result, EIO_PRI_DEFAULT, "my_res_cb", $d);
 // Process request(s)
 eio_event_loop();
}

// Open temporary file
eio_open($tmp_filename, EIO_O_RDONLY, NULL, EIO_PRI_DEFAULT,
  "my_open_cb", $tmp_filename);
eio_event_loop();



with a GDB script :


set env MALLOC_CHECK_=3
run
backtrace full


and produces : 



romain@ubuntu:~$ cat script.gdb | sudo gdb --args /usr/local/bin/php eio-
debug.php
GNU gdb (GDB) 7.5-ubuntu
Copyright (C) 2012 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.  Type "show copying"
and "show warranty" for details.
This GDB was configured as "x86_64-linux-gnu".
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>...
Reading symbols from /usr/local/bin/php...done.
(gdb) (gdb) Starting program: /usr/local/bin/php eio-debug.php
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib/x86_64-linux-gnu/libthread_db.so.1".
[New Thread 0x7ffff7e23700 (LWP 6599)]
string(4) "open"
array(13) {
  ["dev"]=>
  int(64512)
  ["ino"]=>
  int(42512)
  ["mode"]=>
  int(33188)
  ["nlink"]=>
  int(1)
  ["uid"]=>
  int(0)
  ["size"]=>
  int(0)
  ["gid"]=>
  int(0)
  ["rdev"]=>
  int(0)
  ["blksize"]=>
  int(4096)
  ["blocks"]=>
  int(0)
  ["atime"]=>
  int(1365961389)
  ["mtime"]=>
  int(1365961389)
  ["ctime"]=>
  int(1365961389)
}

Program received signal SIGSEGV, Segmentation fault.
[Switching to Thread 0x7ffff7e23700 (LWP 6599)]
0x00007ffff66e98b6 in ?? ()
(gdb) #0  0x00007ffff66e98b6 in ?? ()
No symbol table info available.
#1  0x00007ffff7e23700 in ?? ()
No symbol table info available.
#2  0x0000000001130870 in ?? ()
No symbol table info available.
#3  0x0000000001130870 in ?? ()
No symbol table info available.
#4  0x0000000001131320 in ?? ()
No symbol table info available.
#5  0x0000000000000000 in ?? ()
No symbol table info available.
(gdb) quit
A debugging session is active.

	Inferior 1 [process 6596] will be killed.

Quit anyway? (y or n) [answered Y; input not from terminal]
 [2013-04-14 19:21 UTC] imprec at gmail dot com
Another try with the same procedure gives a different backtrace : 

romain@ubuntu:~$ cat script.gdb | sudo gdb --args /usr/local/bin/php eio-
debug.php
GNU gdb (GDB) 7.5-ubuntu
Copyright (C) 2012 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.  Type "show copying"
and "show warranty" for details.
This GDB was configured as "x86_64-linux-gnu".
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>...
Reading symbols from /usr/local/bin/php...done.
(gdb) (gdb) Starting program: /usr/local/bin/php eio-debug.php
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib/x86_64-linux-gnu/libthread_db.so.1".
[New Thread 0x7ffff7e23700 (LWP 6608)]
string(4) "open"
array(13) {
  ["dev"]=>
  int(64512)
  ["ino"]=>
  int(42512)
  ["mode"]=>
  int(33188)
  ["nlink"]=>
  int(1)
  ["uid"]=>
  int(0)
  ["size"]=>
  int(0)
  ["gid"]=>
  int(0)
  ["rdev"]=>
  int(0)
  ["blksize"]=>
  int(4096)
  ["blocks"]=>
  int(0)
  ["atime"]=>
  int(1365961486)
  ["mtime"]=>
  int(1365961486)
  ["ctime"]=>
  int(1365961486)
}

Program received signal SIGSEGV, Segmentation fault.
[Switching to Thread 0x7ffff7e23700 (LWP 6608)]
0x00007ffff7150d98 in pthread_cond_wait@@GLIBC_2.3.2 () from /lib/x86_64-linux-
gnu/libpthread.so.0
(gdb) #0  0x00007ffff7150d98 in pthread_cond_wait@@GLIBC_2.3.2 () from 
/lib/x86_64-linux-gnu/libpthread.so.0
No symbol table info available.
#1  0x00007ffff66e97be in ?? ()
No symbol table info available.
#2  0x00007ffff7e23700 in ?? ()
No symbol table info available.
#3  0x0000000001130870 in ?? ()
No symbol table info available.
#4  0x0000000001130870 in ?? ()
No symbol table info available.
#5  0x0000000000000000 in ?? ()
No symbol table info available.
(gdb) quit
A debugging session is active.

	Inferior 1 [process 6605] will be killed.

Quit anyway? (y or n) [answered Y; input not from terminal]
 [2013-04-14 20:44 UTC] osmanov@php.net
I meant "pthreads" PECL extension. OK.

However, still the same cryptic output. Nothing interesting.
Let's try the following:

1. Compile PHP with debug support, e.g.:
$ cd /opt/src/php
$ ./configure --prefix=/usr/local --enable-debug
$ make clean && make
$ sudo make install

2. Re-compile eio with debug support:
$ sudo pecl uninstall
$ sudo pecl install eio
... Choose "yes" for debug

3. Show and run the script:
$ cat eio-debug.php
$ USE_ZEND_ALLOC=0 gdb /usr/local/bin/php
gdb> r eio-debug.php
gdb> bt
 [2013-04-14 20:46 UTC] osmanov@php.net
Sorry, in the previous comment second step should be
$ sudo pecl uninstall eio
$ sudo pecl install eio
 [2013-04-14 20:49 UTC] osmanov@php.net
I can ssh to your machine and try it myself if you want.
 [2013-04-14 23:42 UTC] imprec at gmail dot com
Okay, tomorrow, I'll provide a dedicated box that reproduce the problem as soon as 
I will be at the office.

I don't manage to get a correct backtrace with debug symbols
 [2013-04-15 11:13 UTC] imprec at gmail dot com
Hello,

I setup a dedicated box for you, but the seg fault does not occur on this one. As 
the seg fault happens in a Virtual Box VM I run on my computer, I guess this is 
related to slow filesystems.

Would you like to retrieve my VirtualBox VM ?
 [2013-04-15 12:24 UTC] osmanov@php.net
It's nice that it is not reproduced on real machine/OS.

Well, I'd like to get the VM snapshot, if it is not too large(< 500M) ;)
 [2013-07-24 18:46 UTC] osmanov@php.net
-Status: Open +Status: Closed -Assigned To: +Assigned To: osmanov
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Wed Apr 24 23:01:34 2024 UTC