Skip to content

Commit

Permalink
Fixed the bug that recreate coroutine after worker exited (#587)
Browse files Browse the repository at this point in the history
Co-authored-by: Deeka Wong <[email protected]>
  • Loading branch information
huangdijia and huangdijia committed Mar 12, 2024
1 parent b9bca0b commit 797b752
Showing 1 changed file with 15 additions and 9 deletions.
24 changes: 15 additions & 9 deletions src/HttpClient/HttpClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,9 @@ class HttpClient extends \Sentry\HttpClient\HttpClient

protected ?Concurrent $concurrent = null;

protected bool $waitingWorkerExit = false;
protected ?Coroutine $waitingWorkerExit = null;

protected bool $workerExited = false;

public function __construct(
string $sdkIdentifier,
Expand Down Expand Up @@ -67,6 +69,10 @@ protected function loop(): void
return;
}

if ($this->workerExited) {
return;
}

$this->chan = new Channel($this->channelSize);

Coroutine::create(function () {
Expand Down Expand Up @@ -97,13 +103,13 @@ protected function loop(): void
}
});

if (! $this->waitingWorkerExit) {
Coroutine::create(function () {
if (CoordinatorManager::until(Constants::WORKER_EXIT)->yield()) {
$this->close();
}
});
$this->waitingWorkerExit = true;
}
$this->waitingWorkerExit ??= Coroutine::create(function () {
try {
CoordinatorManager::until(Constants::WORKER_EXIT)->yield();
$this->close();
$this->workerExited = true;
} catch (Throwable) {
}
});
}
}

0 comments on commit 797b752

Please sign in to comment.