-
Notifications
You must be signed in to change notification settings - Fork 31
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
Fix #105: Ensure the callback fiber is always alive as long as the event loop lives #107
base: main
Are you sure you want to change the base?
Conversation
…as the event loop lives
Might be enough to simply check for it at the start of run()... |
Ah, interesting. With other event loops this fails, because the event loop resource is destroyed. |
That and you can't suspend in a destructor in PHP < 8.4 |
I'm not sure whether we can do anything about that - it's destructors in the extension... At least for ext-uv once the destructor is called, it's not usable anymore. |
Re-initializing the event loop handles helps: diff --git a/src/EventLoop/Driver/EvDriver.php b/src/EventLoop/Driver/EvDriver.php
index e0a33a3..3f46e45 100644
--- a/src/EventLoop/Driver/EvDriver.php
+++ b/src/EventLoop/Driver/EvDriver.php
@@ -91,6 +91,8 @@ final class EvDriver extends AbstractDriver
// We need to clear all references to events manually, see
// https://bitbucket.org/osmanov/pecl-ev/issues/31/segfault-in-ev_timer_stop
$this->events = [];
+
+ $this->handle = new \EvLoop();
}
/**
diff --git a/src/EventLoop/Driver/EventDriver.php b/src/EventLoop/Driver/EventDriver.php
index 869c3a9..7327560 100644
--- a/src/EventLoop/Driver/EventDriver.php
+++ b/src/EventLoop/Driver/EventDriver.php
@@ -93,6 +93,9 @@ final class EventDriver extends AbstractDriver
$this->handle->free();
unset($this->handle);
}
+
+ /** @psalm-suppress TooFewArguments https://github.com/JetBrains/phpstorm-stubs/pull/763 */
+ $this->handle = new \EventBase();
}
/**
diff --git a/src/EventLoop/Driver/UvDriver.php b/src/EventLoop/Driver/UvDriver.php
index f46d909..dfd6e63 100644
--- a/src/EventLoop/Driver/UvDriver.php
+++ b/src/EventLoop/Driver/UvDriver.php
@@ -80,6 +80,11 @@ final class UvDriver extends AbstractDriver
};
}
+ public function __destruct()
+ {
+ $this->handle = \uv_loop_new();
+ }
+
/**
* {@inheritdoc}
*/ This may or may not cause a leak (only) in the EventDriver due to https://bitbucket.org/osmanov/pecl-event/issues/50/garbage-collection-issue |
Ping @trowski :) |
Different proposed fix compared to #106.