1
0
mirror of https://github.com/danog/MadelineProto.git synced 2024-11-27 14:34:39 +01:00

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)');
}
$this->destructing = true;
Tools::wait($this->serialize());
Tools::wait($this->serialize(), true);
}
//restore_error_handler();
}
@ -292,7 +292,7 @@ class API extends APIFactory
if (empty($filename)) {
return;
}
Logger::log(\danog\MadelineProto\Lang::$current_lang['serializing_madelineproto']);
//Logger::log(\danog\MadelineProto\Lang::$current_lang['serializing_madelineproto']);
if ($filename == '') {
throw new \danog\MadelineProto\Exception('Empty filename');
@ -309,11 +309,11 @@ class API extends APIFactory
}
$this->serialized = \time();
$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);
Logger::log('Lock acquired, serializing');
//Logger::log('Lock acquired, serializing');
try {
if (!$this->getting_api_id) {
@ -335,7 +335,7 @@ class API extends APIFactory
}
$unlock();
}
Logger::log('Done serializing');
//Logger::log('Done serializing');
return $wrote;
})());

View File

@ -84,7 +84,7 @@ class UpdateLoop extends ResumableSignalLoop
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]);
} 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);
unset($API->updaters[$this->channelId], $API->feeders[$this->channelId]);

View File

@ -547,7 +547,7 @@ class MTProto extends AsyncConstruct implements TLCallback
public function serialize()
{
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);
}
}

View File

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

View File

@ -194,7 +194,7 @@ trait Tools
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) {
$promise = new Coroutine($promise);
@ -218,7 +218,7 @@ trait Tools
} catch (\Throwable $throwable) {
throw new \Error('Loop exceptionally stopped without resolving the promise', 0, $throwable);
}
} while (!$resolved && !Magic::$signaled);
} while (!$resolved && !(Magic::$signaled && !$ignoreSignal));
if ($exception) {
throw $exception;