-
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 garbage collection race condition #106
Conversation
There are still some leftover issues with this approach, caused by the reinitialization of the event loop instance:
|
The problem isn't the destruction of the event loop, but actually the destruction of the callback fiber. This PR does not address that problem, but tries to work around it and runs into other problems as shown by your comment. diff --git a/src/EventLoop/Internal/AbstractDriver.php b/src/EventLoop/Internal/AbstractDriver.php
index 94de316..209c4be 100644
--- a/src/EventLoop/Internal/AbstractDriver.php
+++ b/src/EventLoop/Internal/AbstractDriver.php
@@ -498,9 +498,14 @@ abstract class AbstractDriver implements Driver
{
while (!$this->microtaskQueue->isEmpty() || !$this->callbackQueue->isEmpty()) {
/** @noinspection PhpUnhandledExceptionInspection */
- $yielded = $this->callbackFiber->isStarted()
- ? $this->callbackFiber->resume()
- : $this->callbackFiber->start();
+ if ($this->callbackFiber->isSuspended()) {
+ $yielded = $this->callbackFiber->resume();
+ } else {
+ if ($this->callbackFiber->isTerminated()) {
+ $this->createCallbackFiber();
+ }
+ $yielded = $this->callbackFiber->start();
+ }
if ($yielded !== $this->internalSuspensionMarker) {
$this->createCallbackFiber(); would be a proper fix. Created #107. |
Also fwiw, when I forgot the final |
By the way, #107 also works properly with the "leftover issue" from your comment. |
Perfect, it dawned upon me later, your solution solves everything! |
Fixes #105