diff --git a/src/Adapter/Reporter/KafkaClientFactory.php b/src/Adapter/Reporter/KafkaClientFactory.php index 344080b..4a6cf8a 100644 --- a/src/Adapter/Reporter/KafkaClientFactory.php +++ b/src/Adapter/Reporter/KafkaClientFactory.php @@ -22,6 +22,8 @@ use Throwable; use Zipkin\Reporters\Http\ClientFactory; +use function Hyperf\Support\msleep; + class KafkaClientFactory implements ClientFactory { protected ?Channel $chan = null; @@ -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; @@ -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(); } });