Skip to content

Commit

Permalink
Optimize KafkaClientFactory of hyperf/tracer (#6167)
Browse files Browse the repository at this point in the history
  • Loading branch information
huangdijia committed Sep 21, 2023
1 parent 0922d80 commit 67bed75
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/Adapter/Reporter/KafkaClientFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
use Throwable;
use Zipkin\Reporters\Http\ClientFactory;

use function Hyperf\Support\msleep;

class KafkaClientFactory implements ClientFactory
{
protected ?Channel $chan = null;
Expand Down Expand Up @@ -93,7 +95,10 @@ protected function loop(): void
try {
$closure->call($this);
} catch (Throwable) {
$this->producer->close();
try {
$this->producer->close();
} catch (Throwable) {
}
break;
} finally {
$closure = null;
Expand All @@ -106,6 +111,9 @@ protected function loop(): void

Coroutine::create(function () {
if (CoordinatorManager::until(Constants::WORKER_EXIT)->yield()) {
while (! $this->chan->isEmpty()) {
msleep(100);
}
$this->close();
}
});
Expand Down

0 comments on commit 67bed75

Please sign in to comment.