diff --git a/src/danog/MadelineProto/DataCenter.php b/src/danog/MadelineProto/DataCenter.php index 5b58472b..299e2ae1 100644 --- a/src/danog/MadelineProto/DataCenter.php +++ b/src/danog/MadelineProto/DataCenter.php @@ -115,7 +115,7 @@ class DataCenter [ new Nameserver('https://mozilla.cloudflare-dns.com/dns-query'), new Nameserver('https://google.com/resolve', Nameserver::GOOGLE_JSON, ["Host" => "dns.google.com"]), - ], + ] ); $this->DoHClient = Magic::$altervista || Magic::$zerowebhost ? new Rfc1035StubResolver() : new Rfc8484StubResolver($DoHConfig); $this->NonProxiedDoHClient = Magic::$altervista || Magic::$zerowebhost ? new Rfc1035StubResolver() : new Rfc8484StubResolver($NonProxiedDoHConfig); diff --git a/src/danog/MadelineProto/Loop/Connection/ReadLoop.php b/src/danog/MadelineProto/Loop/Connection/ReadLoop.php index 2858316f..f124b1eb 100644 --- a/src/danog/MadelineProto/Loop/Connection/ReadLoop.php +++ b/src/danog/MadelineProto/Loop/Connection/ReadLoop.php @@ -25,6 +25,7 @@ use danog\MadelineProto\Loop\Impl\SignalLoop; use danog\MadelineProto\MTProtoTools\Crypt; use danog\MadelineProto\NothingInTheSocketException; use danog\MadelineProto\Tools; +use Amp\ByteStream\StreamException; /** * Socket read loop. @@ -56,10 +57,11 @@ class ReadLoop extends SignalLoop while (true) { try { $error = yield $this->waitSignal($this->readMessage()); - } catch (NothingInTheSocketException $e) { + } catch (NothingInTheSocketException|StreamException $e) { if (isset($connection->old)) { return; } + $API->logger->logger($e); $API->logger->logger("Got nothing in the socket in DC {$datacenter}, reconnecting...", Logger::ERROR); yield $connection->reconnect(); continue; diff --git a/src/danog/MadelineProto/Loop/Connection/WriteLoop.php b/src/danog/MadelineProto/Loop/Connection/WriteLoop.php index 34683034..0fcd7d9f 100644 --- a/src/danog/MadelineProto/Loop/Connection/WriteLoop.php +++ b/src/danog/MadelineProto/Loop/Connection/WriteLoop.php @@ -24,6 +24,7 @@ use danog\MadelineProto\Loop\Impl\ResumableSignalLoop; use danog\MadelineProto\Magic; use danog\MadelineProto\MTProtoTools\Crypt; use danog\MadelineProto\Tools; +use Amp\ByteStream\StreamException; /** * Socket write loop. @@ -64,7 +65,7 @@ class WriteLoop extends ResumableSignalLoop try { $please_wait = yield $this->{$connection->temp_auth_key === null ? 'unencryptedWriteLoopAsync' : 'encryptedWriteLoopAsync'}(); - } catch (\Amp\ByteStream\StreamException $e) { + } catch (StreamException $e) { if (isset($connection->old)) { return; } diff --git a/src/danog/MadelineProto/Stream/Transport/DefaultStream.php b/src/danog/MadelineProto/Stream/Transport/DefaultStream.php index dfdf49f0..9b4a3fdb 100644 --- a/src/danog/MadelineProto/Stream/Transport/DefaultStream.php +++ b/src/danog/MadelineProto/Stream/Transport/DefaultStream.php @@ -25,6 +25,7 @@ use danog\MadelineProto\Stream\RawStreamInterface; use function Amp\Socket\connect; use function Amp\Socket\cryptoConnect; use danog\MadelineProto\Stream\ProxyStreamInterface; +use Amp\ByteStream\ClosedException; /** * Default stream wrapper. @@ -83,6 +84,9 @@ class DefaultStream extends Socket implements RawStreamInterface, ProxyStreamInt */ public function write(string $data): Promise { + if (!$this->stream) { + throw new ClosedException("MadelineProto stream was disconnected"); + } return $this->stream->write($data); } diff --git a/src/polyfill.php b/src/polyfill.php index 405e2bcb..9cc94611 100644 --- a/src/polyfill.php +++ b/src/polyfill.php @@ -12,3 +12,6 @@ if (!function_exists('is_iterable')) { return is_array($var) || $var instanceof Traversable; } } +if (!function_exists('error_clear_last')) { + function error_clear_last() {} +}