Fix CHANNEL_INVALID errors

This commit is contained in:
Daniil Gentili 2019-09-12 17:54:43 +00:00
parent dad344b18b
commit f15c8fa278
6 changed files with 13 additions and 10 deletions

2
docs

@ -1 +1 @@
Subproject commit 9a873608310b43395032755c35bbdf17d35e23d7 Subproject commit fe346258733323e5173e674f15059dea1a1eb880

View File

@ -197,7 +197,7 @@ class API extends APIFactory
Logger::log('Shutting down MadelineProto (normally or due to an exception, idk)'); Logger::log('Shutting down MadelineProto (normally or due to an exception, idk)');
} }
$this->destructing = true; $this->destructing = true;
Tools::wait($this->serialize()); Tools::wait($this->serialize(), true);
} }
//restore_error_handler(); //restore_error_handler();
} }
@ -292,7 +292,7 @@ class API extends APIFactory
if (empty($filename)) { if (empty($filename)) {
return; return;
} }
Logger::log(\danog\MadelineProto\Lang::$current_lang['serializing_madelineproto']); //Logger::log(\danog\MadelineProto\Lang::$current_lang['serializing_madelineproto']);
if ($filename == '') { if ($filename == '') {
throw new \danog\MadelineProto\Exception('Empty filename'); throw new \danog\MadelineProto\Exception('Empty filename');
@ -309,11 +309,11 @@ class API extends APIFactory
} }
$this->serialized = \time(); $this->serialized = \time();
$realpaths = Serialization::realpaths($filename); $realpaths = Serialization::realpaths($filename);
Logger::log('Waiting for exclusive lock of serialization lockfile...'); //Logger::log('Waiting for exclusive lock of serialization lockfile...');
$unlock = yield Tools::flock($realpaths['lockfile'], LOCK_EX); $unlock = yield Tools::flock($realpaths['lockfile'], LOCK_EX);
Logger::log('Lock acquired, serializing'); //Logger::log('Lock acquired, serializing');
try { try {
if (!$this->getting_api_id) { if (!$this->getting_api_id) {
@ -335,7 +335,7 @@ class API extends APIFactory
} }
$unlock(); $unlock();
} }
Logger::log('Done serializing'); //Logger::log('Done serializing');
return $wrote; return $wrote;
})()); })());

View File

@ -84,7 +84,7 @@ class UpdateLoop extends ResumableSignalLoop
try { try {
$difference = yield $API->method_call_async_read('updates.getChannelDifference', ['channel' => 'channel#'.$this->channelId, 'filter' => ['_' => 'channelMessagesFilterEmpty'], 'pts' => $request_pts, 'limit' => $limit, 'force' => true], ['datacenter' => $API->datacenter->curdc, 'postpone' => $first]); $difference = yield $API->method_call_async_read('updates.getChannelDifference', ['channel' => 'channel#'.$this->channelId, 'filter' => ['_' => 'channelMessagesFilterEmpty'], 'pts' => $request_pts, 'limit' => $limit, 'force' => true], ['datacenter' => $API->datacenter->curdc, 'postpone' => $first]);
} catch (RPCErrorException $e) { } catch (RPCErrorException $e) {
if (\in_array($e->rpc, ['CHANNEL_PRIVATE', 'CHAT_FORBIDDEN'])) { if (\in_array($e->rpc, ['CHANNEL_PRIVATE', 'CHANNEL_INVALID', 'CHAT_FORBIDDEN'])) {
$feeder->signal(true); $feeder->signal(true);
unset($API->updaters[$this->channelId], $API->feeders[$this->channelId]); unset($API->updaters[$this->channelId], $API->feeders[$this->channelId]);

View File

@ -547,7 +547,7 @@ class MTProto extends AsyncConstruct implements TLCallback
public function serialize() public function serialize()
{ {
if ($this->wrapper instanceof API && isset($this->wrapper->session) && !\is_null($this->wrapper->session) && !$this->asyncInitPromise) { if ($this->wrapper instanceof API && isset($this->wrapper->session) && !\is_null($this->wrapper->session) && !$this->asyncInitPromise) {
$this->logger->logger("Didn't serialize in a while, doing that now..."); //$this->logger->logger("Didn't serialize in a while, doing that now...");
$this->wrapper->serialize($this->wrapper->session); $this->wrapper->serialize($this->wrapper->session);
} }
} }

View File

@ -169,6 +169,9 @@ trait PeerHandler
if ($e->rpc === 'CHANNEL_PRIVATE') { if ($e->rpc === 'CHANNEL_PRIVATE') {
return true; return true;
} }
if ($e->rpc === 'CHANNEL_INVALID') {
return true;
}
return false; return false;
} }

View File

@ -194,7 +194,7 @@ trait Tools
return \unpack('d', \danog\MadelineProto\Magic::$BIG_ENDIAN ? \strrev($value) : $value)[1]; return \unpack('d', \danog\MadelineProto\Magic::$BIG_ENDIAN ? \strrev($value) : $value)[1];
} }
public static function wait($promise) public static function wait($promise, $ignoreSignal = false)
{ {
if ($promise instanceof \Generator) { if ($promise instanceof \Generator) {
$promise = new Coroutine($promise); $promise = new Coroutine($promise);
@ -218,7 +218,7 @@ trait Tools
} catch (\Throwable $throwable) { } catch (\Throwable $throwable) {
throw new \Error('Loop exceptionally stopped without resolving the promise', 0, $throwable); throw new \Error('Loop exceptionally stopped without resolving the promise', 0, $throwable);
} }
} while (!$resolved && !Magic::$signaled); } while (!$resolved && !(Magic::$signaled && !$ignoreSignal));
if ($exception) { if ($exception) {
throw $exception; throw $exception;