Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

uv_queue_work() - Error in `zts-php': double free or corruption (fasttop) #46

Open
uasan opened this issue May 27, 2017 · 5 comments
Open

Comments

@uasan
Copy link

uasan commented May 27, 2017

PHP 7.1.5 (cli) (built: May  9 2017 17:55:16) ( ZTS )
Copyright (c) 1997-2017 The PHP Group
Zend Engine v3.1.0, Copyright (c) 1998-2017 Zend Technologies
    with Zend OPcache v7.1.5, Copyright (c) 1999-2017, by Zend Technologies

libuv Support => enabled
Version => 0.2.1
libuv Version => 1.10
<?php

$loop  = uv_default_loop();

$thread = function()
{
	echo "THREAD-CALL\n";
};

$after = function()
{
	echo "THREAD-CALL-AFTER\n";
};

uv_queue_work($loop, $thread, $after);
uv_queue_work($loop, $thread, $after);

$timer = uv_timer_init($loop);

uv_timer_start($timer, 1000, 1000, function()
{
	static $i = 0;

	echo "TIMER: $i\n";

	$i++;
});

uv_run($loop);
*** Error in `zts-php': double free or corruption (fasttop): 0x000055ae15c1b1f0 ***
======= Backtrace: =========
/lib64/libc.so.6(+0x791fb)[0x7f21dc3b81fb]
/lib64/libc.so.6(+0x8288a)[0x7f21dc3c188a]
/lib64/libc.so.6(cfree+0x4c)[0x7f21dc3c52bc]
zts-php(zend_hash_destroy+0x146)[0x55ae146ab706]
zts-php(tsrm_free_interpreter_context+0x4a)[0x55ae146218ea]
/usr/lib64/php-zts/modules/uv.so(+0x1fbb2)[0x7f21d0d23bb2]
/usr/lib64/php-zts/modules/uv.so(+0x1fc60)[0x7f21d0d23c60]
/lib64/libuv.so.1(+0x96d4)[0x7f21d0ae76d4]
/lib64/libpthread.so.0(+0x76ca)[0x7f21ddcd56ca]
/lib64/libc.so.6(clone+0x5f)[0x7f21dc446f7f]
======= Memory map: ========
....
Aborted (core dumped)
@bwoebi
Copy link
Member

bwoebi commented Jun 7, 2017

This thing is very much unsafe … I definitely wouldn't use it currently :x … I probably should remove that thing altogether here.

That's what ext/pthreads is actually for… Use that, if you need threads in a safe way.

@uasan
Copy link
Author

uasan commented Jun 9, 2017

I resolve the cause, this problem in php-ext-raphf is thread not safe, without it everything works well.
Do not delete uv_queue_work() function.

@kelunik
Copy link
Member

kelunik commented Oct 6, 2017

Did you try with PHP 7.2? ZTS is broken in PHP 7.0 and 7.1.

@uasan
Copy link
Author

uasan commented Dec 30, 2017

# zts-php -v

PHP 7.2.0 (cli) (built: Nov 28 2017 19:54:32) ( ZTS )
Copyright (c) 1997-2017 The PHP Group
Zend Engine v3.2.0, Copyright (c) 1998-2017 Zend Technologies

# zts-php test_uv_queue_work.php

THREAD-CALL
THREAD-CALL-AFTER
THREAD-CALL
*** Error in `zts-php': double free or corruption (fasttop): 0x00005557c12a77d0 ***
======= Backtrace: =========
/lib64/libc.so.6(+0x7cbac)[0x7f6b75e1dbac]
/lib64/libc.so.6(+0x87a59)[0x7f6b75e28a59]
/lib64/libc.so.6(cfree+0x16e)[0x7f6b75e2e3be]
zts-php(zend_hash_destroy+0xfa)[0x5557c024ffda]
zts-php(tsrm_free_interpreter_context+0x55)[0x5557c01c57c5]
/usr/lib64/php-zts/modules/uv.so(+0x1e3e9)[0x7f6b72ee43e9]
/usr/lib64/php-zts/modules/uv.so(+0x1e48a)[0x7f6b72ee448a]
/lib64/libuv.so.1(+0x96d4)[0x7f6b72ca96d4]
/lib64/libpthread.so.0(+0x736d)[0x7f6b7776d36d]
/lib64/libc.so.6(clone+0x3f)[0x7f6b75eb1e1f]
...
Aborted (core dumped)

TheTechsTech added a commit to TheTechsTech/php-uv that referenced this issue Mar 16, 2023
added the no real issue amphp#46
@TheTechsTech
Copy link

For future reference, I find the issues with other extensions installed.

Having opcache enabled is the main problem, and using xdebug too does not play well.

I find segmentation faults really happening on type of variables being referenced in the callbacks. Everything executes as expected, but segfaults when done, like using stream_socket_pair()

As the current Windows version does not do after callbacks, but using uv_async_send that behavior can be achieved, create a thread queue for the callbacks.

So removing #83 not really a good idea.

TheTechsTech added a commit to symplely/thread_queue that referenced this issue Mar 19, 2023
- some testing under PHPunit works best with `@runInSeparateProcess`
- skip channel test under PHPunit long stall before segfault, no segfault under Windows though
- update `Thread` class to properly handle multi arguments, docblock comment about cancel
- these additions in reference to amphp/ext-uv#46
TheTechsTech added a commit to symplely/ext-uv that referenced this issue Apr 7, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

4 participants