Improve retry management

This commit is contained in:
Daniil Gentili 2018-03-03 18:16:01 +00:00
parent 28921b4db4
commit b2b5c97753
4 changed files with 7 additions and 5 deletions

View File

@ -48,6 +48,7 @@ class Connection
public $ack_queue = [];
public $i = [];
public $must_open = false;
public $last_recv = 0;
public function __magic_construct($proxy, $extra, $ip, $port, $protocol, $timeout, $ipv6)
{

View File

@ -85,7 +85,7 @@ trait CallHandler
$serialized = $this->serialize_object(['type' => 'gzip_packed'], ['packed_data' => $gzipped], 'gzipped data');
\danog\MadelineProto\Logger::log('Using GZIP compression for '.$method.', saved '.($l - $g).' bytes of data, reduced call size by '.$g * 100 / $l.'%', \danog\MadelineProto\Logger::ULTRA_VERBOSE);
}
$last_recv = $this->last_recv;
$last_recv = $this->datacenter->sockets[$aargs['datacenter']]->last_recv;
for ($count = 1; $count <= $this->settings['max_tries']['query']; $count++) {
if ($canunset = !$this->updates_state['sync_loading']) {
$this->updates_state['sync_loading'] = true;
@ -185,7 +185,7 @@ trait CallHandler
} catch (\danog\MadelineProto\NothingInTheSocketException $e) {
$last_error = 'Nothing in the socket';
\danog\MadelineProto\Logger::log('An error getting response of method '.$method.': '.$e->getMessage().' in '.basename($e->getFile(), '.php').' on line '.$e->getLine().'. Retrying...', \danog\MadelineProto\Logger::WARNING);
if ($res_count > 3) {
if ($res_count > 3 && $last_recv === $this->datacenter->sockets[$aargs['datacenter']]->last_recv) {
$this->close_and_reopen($aargs['datacenter']);
}
continue; //2;
@ -222,6 +222,7 @@ trait CallHandler
if ($this->authorized_dc === -1 && $method === 'users.getUsers' && $args = ['id' => [['_' => 'inputUserSelf']]]) {
$this->authorized_dc = $this->datacenter->curdc;
}
$last_recv = $this->datacenter->sockets[$aargs['datacenter']]->last_recv;
\danog\MadelineProto\Logger::log($e->getMessage(), \danog\MadelineProto\Logger::WARNING);
continue;
}
@ -251,7 +252,7 @@ trait CallHandler
}
}
if ($server_answer === null) {
if ($last_recv === $this->last_recv && $this->datacenter->sockets[$aargs['datacenter']]->temp_auth_key !== null) {
if ($last_recv === $this->datacenter->sockets[$aargs['datacenter']]->last_recv && $this->datacenter->sockets[$aargs['datacenter']]->temp_auth_key !== null) {
\danog\MadelineProto\Logger::log('WARNING: Resetting auth key...', \danog\MadelineProto\Logger::WARNING);
$this->datacenter->sockets[$aargs['datacenter']]->temp_auth_key = null;
$this->init_authorization();

View File

@ -150,7 +150,7 @@ trait MessageHandler
$this->datacenter->sockets[$datacenter]->incoming_messages[$message_id]['content'] = $deserialized;
$this->datacenter->sockets[$datacenter]->incoming_messages[$message_id]['response'] = -1;
$this->datacenter->sockets[$datacenter]->new_incoming[$message_id] = $message_id;
$this->last_recv = time();
$this->datacenter->sockets[$datacenter]->last_recv = time();
return true;
}

View File

@ -97,7 +97,7 @@ trait UpdateHandler
$only_updates = $this->handle_messages($this->datacenter->curdc);
} catch (\danog\MadelineProto\NothingInTheSocketException $e) {
}
if (time() - $this->last_recv > $this->settings['updates']['getdifference_interval']) {
if (time() - $this->datacenter->sockets[$this->datacenter->curdc]->last_recv > $this->settings['updates']['getdifference_interval']) {
$this->get_updates_difference();
}
} catch (\danog\MadelineProto\RPCErrorException $e) {