Closed optiman closed 6 years ago
We can't really do anything about segfaults, please report them to bugs.php.net. Do you have xdebug
or pthreads
enabled?
No, xdebug
and pthreads
are not enabled.
Tried this locally on 7.2.0 (with and without xdebug
) and had no issue making the second parameter very large. We've been seeing segfaults with any code using amphp/process
when usingxdebug
or phpdbg
on travis. Maybe the stacktrace you provided would be useful to @bwoebi for debugging.
Ok, I think I found the problem - it's ev
extension.
I disabled it and segfault is gone with both stream_select
and uv
.
Sorry for bothering you all, I'm closing this issue as it is not related to the library itself.
@optiman If you have time, could you test whether the patch mentioned in https://bitbucket.org/osmanov/pecl-ev/issues/31/segfault-in-ev_timer_stop fixes the segfault with ev
enabled? I didn't have time to test it and then forgot about it.
Yes, it fixes segfault but adds a notice for every spawned process:
PHP Notice: Trying to get property 'is_active' of non-object
Here:
public function __destruct()
{
// foreach ($this->events as $event) {
// $event->stop();
foreach ($this->events as &$event) {
if ($event->is_active) {
$event->stop();
$event = null;
}
}
}
$event
is null
.
Could you var_dump($this->events);
?
var_dump($this->events);
array(3) { ["b"]=> NULL ["c"]=> object(EvIo)#45 (6) { ["fd"]=> resource(73) of type (stream) ["events"]=> int(1) ["is_active"]=> bool(true) ["data"]=> object(Amp\Loop\Watcher)#44 (8) { ["type"]=> int(1) ["enabled"]=> bool(true) ["referenced"]=> bool(false) ["id"]=> string(1) "c" ["callback"]=> object(Closure)#43 (2) { ["static"]=> array(4) { ["deferred"]=> &object(Amp\Deferred)#31 (4) { ["resolved":"Amp\Deferred":private]=> bool(false) ["result":"Amp\Deferred":private]=> NULL ["onResolved":"Amp\Deferred":private]=> object(Closure)#63 (2) { ["this"]=> object(Amp\Coroutine)#61 (9) { ["generator":"Amp\Coroutine":private]=> object(Generator)#60 (0) { } ["onResolve":"Amp\Coroutine":private]=> *RECURSION* ["immediate":"Amp\Coroutine":private]=> bool(true) ["exception":"Amp\Coroutine":private]=> NULL ["value":"Amp\Coroutine":private]=> NULL ["resolved":"Amp\Coroutine":private]=> bool(false) ["result":"Amp\Coroutine":private]=> NULL ["onResolved":"Amp\Coroutine":private]=> object(Closure)#64 (2) { ["this"]=> object(Amp\Coroutine)#54 (9) { ["generator":"Amp\Coroutine":private]=> object(Generator)#53 (0) { } ["onResolve":"Amp\Coroutine":private]=> *RECURSION* ["immediate":"Amp\Coroutine":private]=> bool(true) ["exception":"Amp\Coroutine":private]=> NULL ["value":"Amp\Coroutine":private]=> NULL ["resolved":"Amp\Coroutine":private]=> bool(false) ["result":"Amp\Coroutine":private]=> NULL ["onResolved":"Amp\Coroutine":private]=> object(Closure)#65 (1) { ["parameter"]=> array(1) { ["$exception"]=> string(10) "" } } ["resolutionTrace":"Amp\Coroutine":private]=> NULL } ["parameter"]=> array(2) { ["$exception"]=> string(10) " " ["$value"]=> string(10) " " } } ["resolutionTrace":"Amp\Coroutine":private]=> NULL } ["parameter"]=> array(2) { ["$exception"]=> string(10) " " ["$value"]=> string(10) " " } } ["resolutionTrace":"Amp\Deferred":private]=> NULL } ["readable"]=> &bool(true) ["chunkSize"]=> int(8192) ["useFread"]=> bool(true) } ["parameter"]=> array(2) { ["$watcher"]=> string(10) " " ["$stream"]=> string(10) " " } } ["data"]=> NULL ["value"]=> resource(55) of type (stream) ["__propertySuggestThreshold":"Amp\Loop\Watcher":private]=> int(70) } ["is_pending"]=> bool(false) ["priority"]=> int(0) } ["e"]=> object(EvIo)#32 (6) { ["fd"]=> resource(74) of type (stream) ["events"]=> int(1) ["is_active"]=> bool(true) ["data"]=> object(Amp\Loop\Watcher)#46 (8) { ["type"]=> int(1) ["enabled"]=> bool(true) ["referenced"]=> bool(false) ["id"]=> string(1) "e" ["callback"]=> array(2) { [0]=> string(33) "Amp\Process\Internal\Posix\Runner" [1]=> string(33) "onProcessEndExtraDataPipeReadable" } ["data"]=> object(Amp\Process\Internal\Posix\Handle)#23 (12) { ["joinDeferred"]=> object(Amp\Deferred)#25 (4) { ["resolved":"Amp\Deferred":private]=> bool(false) ["result":"Amp\Deferred":private]=> NULL ["onResolved":"Amp\Deferred":private]=> NULL ["resolutionTrace":"Amp\Deferred":private]=> NULL } ["proc"]=> resource(57) of type (process) ["extraDataPipe"]=> resource(56) of type (stream) ["extraDataPipeWatcher"]=> string(1) "e" ["extraDataPipeStartWatcher"]=> string(1) "d" ["originalParentPid"]=> int(22454) ["stdin"]=> object(Amp\Process\ProcessOutputStream)#27 (4) { ["queuedWrites":"Amp\Process\ProcessOutputStream":private]=> array(0) { } ["shouldClose":"Amp\Process\ProcessOutputStream":private]=> bool(false) ["resourceStream":"Amp\Process\ProcessOutputStream":private]=> object(Amp\ByteStream\ResourceOutputStream)#35 (5) { ["resource":"Amp\ByteStream\ResourceOutputStream":private]=> &resource(53) of type (stream) ["watcher":"Amp\ByteStream\ResourceOutputStream":private]=> string(1) "a" ["writes":"Amp\ByteStream\ResourceOutputStream":private]=> object(SplQueue)#36 (2) { ["flags":"SplDoublyLinkedList":private]=> int(4) ["dllist":"SplDoublyLinkedList":private]=> array(0) { } } ["writable":"Amp\ByteStream\ResourceOutputStream":private]=> &bool(true) ["chunkSize":"Amp\ByteStream\ResourceOutputStream":private]=> NULL } ["error":"Amp\Process\ProcessOutputStream":private]=> NULL } ["stdout"]=> object(Amp\Process\ProcessInputStream)#30 (5) { ["initialRead":"Amp\Process\ProcessInputStream":private]=> NULL ["shouldClose":"Amp\Process\ProcessInputStream":private]=> bool(false) ["referenced":"Amp\Process\ProcessInputStream":private]=> bool(true) ["resourceStream":"Amp\Process\ProcessInputStream":private]=> object(Amp\ByteStream\ResourceInputStream)#39 (4) { ["resource":"Amp\ByteStream\ResourceInputStream":private]=> resource(54) of type (stream) ["watcher":"Amp\ByteStream\ResourceInputStream":private]=> string(1) "b" ["deferred":"Amp\ByteStream\ResourceInputStream":private]=> &NULL ["readable":"Amp\ByteStream\ResourceInputStream":private]=> &bool(true) } ["error":"Amp\Process\ProcessInputStream":private]=> NULL } ["stderr"]=> object(Amp\Process\ProcessInputStream)#33 (5) { ["initialRead":"Amp\Process\ProcessInputStream":private]=> NULL ["shouldClose":"Amp\Process\ProcessInputStream":private]=> bool(false) ["referenced":"Amp\Process\ProcessInputStream":private]=> bool(false) ["resourceStream":"Amp\Process\ProcessInputStream":private]=> object(Amp\ByteStream\ResourceInputStream)#42 (4) { ["resource":"Amp\ByteStream\ResourceInputStream":private]=> resource(55) of type (stream) ["watcher":"Amp\ByteStream\ResourceInputStream":private]=> string(1) "c" ["deferred":"Amp\ByteStream\ResourceInputStream":private]=> &object(Amp\Deferred)#31 (4) { ["resolved":"Amp\Deferred":private]=> bool(false) ["result":"Amp\Deferred":private]=> NULL ["onResolved":"Amp\Deferred":private]=> object(Closure)#63 (2) { ["this"]=> object(Amp\Coroutine)#61 (9) { ["generator":"Amp\Coroutine":private]=> object(Generator)#60 (0) { } ["onResolve":"Amp\Coroutine":private]=> *RECURSION* ["immediate":"Amp\Coroutine":private]=> bool(true) ["exception":"Amp\Coroutine":private]=> NULL ["value":"Amp\Coroutine":private]=> NULL ["resolved":"Amp\Coroutine":private]=> bool(false) ["result":"Amp\Coroutine":private]=> NULL ["onResolved":"Amp\Coroutine":private]=> object(Closure)#64 (2) { ["this"]=> object(Amp\Coroutine)#54 (9) { ["generator":"Amp\Coroutine":private]=> object(Generator)#53 (0) { } ["onResolve":"Amp\Coroutine":private]=> *RECURSION* ["immediate":"Amp\Coroutine":private]=> bool(true) ["exception":"Amp\Coroutine":private]=> NULL ["value":"Amp\Coroutine":private]=> NULL ["resolved":"Amp\Coroutine":private]=> bool(false) ["result":"Amp\Coroutine":private]=> NULL ["onResolved":"Amp\Coroutine":private]=> object(Closure)#65 (1) { ["parameter"]=> array(1) { ["$exception"]=> string(10) " " } } ["resolutionTrace":"Amp\Coroutine":private]=> NULL } ["parameter"]=> array(2) { ["$exception"]=> string(10) " " ["$value"]=> string(10) " " } } ["resolutionTrace":"Amp\Coroutine":private]=> NULL } ["parameter"]=> array(2) { ["$exception"]=> string(10) " " ["$value"]=> string(10) " " } } ["resolutionTrace":"Amp\Deferred":private]=> NULL } ["readable":"Amp\ByteStream\ResourceInputStream":private]=> &bool(true) } ["error":"Amp\Process\ProcessInputStream":private]=> NULL } ["pidDeferred"]=> object(Amp\Deferred)#24 (4) { ["resolved":"Amp\Deferred":private]=> bool(true) ["result":"Amp\Deferred":private]=> int(22458) ["onResolved":"Amp\Deferred":private]=> NULL ["resolutionTrace":"Amp\Deferred":private]=> NULL } ["status"]=> int(1) ["__propertySuggestThreshold":"Amp\Process\Internal\ProcessHandle":private]=> int(70) } ["value"]=> resource(56) of type (stream) ["__propertySuggestThreshold":"Amp\Loop\Watcher":private]=> int(70) } ["is_pending"]=> bool(false) ["priority"]=> int(0) } }
Does it work if you remove the reference from the foreach, so foreach ($this->events as $event)
instead of foreach ($this->events as &$event)
?
No, reference doesn't matter. The first array element $this->events['b']
simply is null
.
We have released Amp v2.0.5 which fixes this.
If I spawn 10 (or more) processes, regardless what they do (sleeping for 5 seconds in this case) - I'm receiving segmentation fault at the end, even though spawned processes seem to exit properly. When spawning 8 or less processes, everything is fine.
Code:
Result:
Backtrace: