Skip to content

Commit b2b68c6

Browse files
committed
Resolve segfaulting issues with pecl-ev
1 parent 8e847ea commit b2b68c6

File tree

5 files changed

+33
-24
lines changed

5 files changed

+33
-24
lines changed

.travis.yml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,10 @@ matrix:
1010
allow_failures:
1111
- php: hhvm
1212

13+
before_script:
14+
- sudo apt-get install gdb
15+
1316
install: ./travis-init.sh
1417

1518
script:
16-
- phpunit --coverage-text
19+
- phpunit --coverage-text

script.gdb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
set env MALLOC_CHECK_=3
2+
run
3+
backtrace full

src/ExtEvLoop.php

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ class ExtEvLoop implements LoopInterface
1616
private $timers;
1717
private $readEvents = array();
1818
private $writeEvents = array();
19+
1920
private $running = false;
2021

2122
public function __construct()
@@ -58,7 +59,7 @@ public function removeReadStream($stream)
5859
{
5960
$key = (int) $stream;
6061
if(isset($this->readEvents[$key])) {
61-
$this->readEvents[$key]->stop();
62+
$this->readEvents[$key]->stop();
6263
unset($this->readEvents[$key]);
6364
}
6465
}
@@ -72,8 +73,8 @@ public function removeWriteStream($stream)
7273
{
7374
$key = (int) $stream;
7475
if(isset($this->writeEvents[$key])) {
75-
$this->writeEvents[(int)$stream]->stop();
76-
unset($this->writeEvents[(int)$stream]);
76+
$this->writeEvents[$key]->stop();
77+
unset($this->writeEvents[$key]);
7778
}
7879
}
7980

@@ -147,7 +148,11 @@ public function cancelTimer(TimerInterface $timer)
147148
if (isset($this->timers[$timer])) {
148149
/* stop EvTimer */
149150
$this->timers[$timer]->stop();
150-
$this->timers->detach($timer);
151+
152+
/* defer timer */
153+
$this->nextTick(function() use ($timer) {
154+
$this->timers->detach($timer);
155+
});
151156
}
152157
}
153158

@@ -225,4 +230,20 @@ public function stop()
225230
{
226231
$this->running = false;
227232
}
233+
234+
public function __destruct()
235+
{
236+
// mannually stop all watchers
237+
foreach($this->timers as $timer) {
238+
$this->timers[$timer]->stop();
239+
}
240+
241+
foreach($this->readEvents as $event) {
242+
$event->stop();
243+
}
244+
245+
foreach($this->writeEvents as $event) {
246+
$event->stop();
247+
}
248+
}
228249
}

tests/AbstractLoopTest.php

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -355,25 +355,6 @@ function () {
355355
$this->loop->run();
356356
}
357357

358-
public function testPeriodTimerExecutes()
359-
{
360-
$count = 0;
361-
$this->loop->addPeriodicTimer(
362-
0.001,
363-
function ($timer) use (&$count) {
364-
echo 'tick';
365-
$count++;
366-
if($count === 3) {
367-
$timer->cancel();
368-
}
369-
}
370-
);
371-
372-
$this->expectOutputString('tickticktick');
373-
374-
$this->loop->run();
375-
}
376-
377358
public function testFutureTick()
378359
{
379360
$called = false;

travis-init.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ if [ "$TRAVIS_PHP_VERSION" != "hhvm" ]; then
2727
phpize
2828
./configure
2929
make
30+
# make test
3031
make install
3132
popd
3233
echo "extension=ev.so" >> "$(php -r 'echo php_ini_loaded_file();')"

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy