From 2614c863a493519199f582509d9f4329e37ec44f Mon Sep 17 00:00:00 2001 From: Daniil Gentili Date: Tue, 4 Jun 2019 18:24:25 +0200 Subject: [PATCH] Handle stream errors --- .../MadelineProto/Loop/Connection/WriteLoop.php | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/src/danog/MadelineProto/Loop/Connection/WriteLoop.php b/src/danog/MadelineProto/Loop/Connection/WriteLoop.php index a904c465..c5481e1d 100644 --- a/src/danog/MadelineProto/Loop/Connection/WriteLoop.php +++ b/src/danog/MadelineProto/Loop/Connection/WriteLoop.php @@ -60,12 +60,16 @@ class WriteLoop extends ResumableSignalLoop $API->logger->logger("Done waiting in $this", Logger::ULTRA_VERBOSE); } - if ($connection->temp_auth_key === null) { - $res = $this->unencryptedWriteLoopAsync(); - } else { - $res = $this->encryptedWriteLoopAsync(); + try { + $please_wait = yield $this->{$connection->temp_auth_key === null ? 'unencryptedWriteLoopAsync' : 'encryptedWriteLoopAsync'}(); + } catch (Amp\ByteStream\StreamException $e) { + if (isset($connection->old)) { + return; + } + $API->logger->logger("Got nothing in the socket in DC {$datacenter}, reconnecting...", Logger::ERROR); + yield $connection->reconnect(); + continue; } - $please_wait = yield $res; //$connection->waiter->resume(); }