chobie / php-uv

libuv php extension
185 stars 21 forks source link

Coredump on Ubuntu when using polls #40

Open csaoh opened 11 years ago

csaoh commented 11 years ago

This code (the example code from uv_poll_start with only php://stdout replaced)

<?php
$fd = fopen("php://temp","w+");

$poll = uv_poll_init(uv_default_loop(), $fd);
uv_poll_start($poll, UV::WRITABLE, function($poll, $stat, $ev, $conn){
        fwrite($conn, "Hello");
        fclose($conn);
        uv_poll_stop($poll);
});

uv_run();

results in

Aborted (core dumped)

It works fine on OS X though.

(I had to use gcc4.4 as described in #24 to make it work in the first place)

chobie commented 11 years ago

hmm. I have to take a look around php's "php://temp" implementation. epoll returns EPERM error at this time. so i guess it's not using file descriptor.

Program received signal SIGABRT, Aborted.
0x00007ffff55a8425 in raise () from /lib/x86_64-linux-gnu/libc.so.6
(gdb) bt
#0  0x00007ffff55a8425 in raise () from /lib/x86_64-linux-gnu/libc.so.6
#1  0x00007ffff55abb8b in abort () from /lib/x86_64-linux-gnu/libc.so.6
#2  0x00007ffff0cbccc6 in uv__io_poll (loop=0x7ffff0ed81c0, timeout=-1) at src/unix/linux/linux-core.c:162
#3  0x00007ffff0ca73bd in uv_run (loop=0x7ffff0ed81c0, mode=UV_RUN_DEFAULT) at src/unix/core.c:294
#4  0x00007ffff0c98434 in zif_uv_run (ht=0, return_value=0x7ffff7fcfa78, return_value_ptr=0x0, this_ptr=0x0, return_value_used=0)
    at /home/chobie/src/src/php-uv/php_uv.c:3353
#5  0x00000000009fd967 in execute_internal (execute_data_ptr=0x7ffff7f9b0e8, return_value_used=0) at /var/tmp/php-build/source/5.4.12/Zend/zend_execute.c:1480
#6  0x00007ffff0ee88bb in xdebug_execute_internal (current_execute_data=0x7ffff7f9b0e8, return_value_used=0)
    at /var/tmp/php-build/source/xdebug-2.2.1/xdebug.c:1483
#7  0x00000000009ff554 in zend_do_fcall_common_helper_SPEC (execute_data=0x7ffff7f9b0e8) at /var/tmp/php-build/source/5.4.12/Zend/zend_vm_execute.h:644
#8  0x0000000000a06798 in ZEND_DO_FCALL_SPEC_CONST_HANDLER (execute_data=0x7ffff7f9b0e8) at /var/tmp/php-build/source/5.4.12/Zend/zend_vm_execute.h:2223
#9  0x00000000009fde0e in execute (op_array=0x7ffff7fd08b8) at /var/tmp/php-build/source/5.4.12/Zend/zend_vm_execute.h:410
#10 0x00007ffff0ee8441 in xdebug_execute (op_array=0x7ffff7fd08b8) at /var/tmp/php-build/source/xdebug-2.2.1/xdebug.c:1391
#11 0x00000000009c018f in zend_execute_scripts (type=8, retval=0x0, file_count=3) at /var/tmp/php-build/source/5.4.12/Zend/zend.c:1315
#12 0x000000000093367c in php_execute_script (primary_file=0x7fffffffd6c0) at /var/tmp/php-build/source/5.4.12/main/main.c:2492
#13 0x0000000000b09455 in do_cli (argc=2, argv=0x7fffffffeaa8) at /var/tmp/php-build/source/5.4.12/sapi/cli/php_cli.c:988
#14 0x0000000000b0a58e in main (argc=2, argv=0x7fffffffeaa8) at /var/tmp/php-build/source/5.4.12/sapi/cli/php_cli.c:1364
(gdb) q
csaoh commented 11 years ago

i does the same with any file, if i recall it right. will doublecheck tomorrow

chobie commented 11 years ago

o.O. probably i missed something. i'll check this in this weekend.

csaoh commented 11 years ago

Yep, i confirm,

<?php
$fd = fopen("testfile","w+");

$poll = uv_poll_init(uv_default_loop(), $fd);
uv_poll_start($poll, UV::WRITABLE, function($poll, $stat, $ev, $conn){
        fwrite($conn, "Hello");
        fclose($conn);
        uv_poll_stop($poll);
});

uv_run();

results in the same thing. Same for UV::READABLE flag

csaoh commented 11 years ago

Looks like it enters

if (uv__epoll_ctl(loop->backend_fd, op, w->fd, &e)) {
      if (errno != EEXIST)
        abort();

in linux.core.c, line 160

csaoh commented 11 years ago

Alriiiight. It's a problem within libuv. When I asked about it on IRC, i got answered "not very nice, but uv_poll_t is not meant to work with files". Sooo, i don't really know what to do about it.

Either someone (I'll give a look at it right now) fixes the issue on linux, or I have to find another way to do it, and I'm pretty positive I can't use uv_fs_poll since it doesn't take an fd, and for react I need it...

chobie commented 11 years ago

@csaoh thank you for asking on IRC. I also realized it's libuv issue. it's able to work with node-v0.8.21 tag.

for now, let's switch libuv version.

csaoh commented 11 years ago

Now it does nothing at all, both on OSX and linux. I also have this message

[Thu Feb 28 14:24:31 2013]  Script:  '/Users/andrey/test.php'
/Users/andrey/www/php-libev/libev.c(396) :  Freeing 0x10DAEAD88 (8 bytes), script=/Users/andrey/test.php
Last leak repeated 4 times
=== Total 5 memory leaks detected ===
chobie commented 11 years ago

hmm. my osx and ubuntu box passed the testcases. probably did you forget git submodule update after git pull --rebase ? i updated submodule reference so it requires update and re-generate uv.

git pull --rebase
git submodule update
phpize --clean
cd libuv
make clean
make
# now, it generate uv.a
cd ..
./configure
make

and that error message did not (directly) relate php-uv. just php-libev doesn't free some emalloc'ed variables.

csaoh commented 11 years ago

Sorry, works fine !

steverhoades commented 10 years ago

Unfortunately, this issue is still present as of 1.0.0-rc2. I have added a test in my PR #59 to account for this. I think that it might make more sense to only allow fds that uv_poll_init can act on, and throw E_ERRORS for any stream types that are not of type *socket ?