More logs and hotfix

This commit is contained in:
Daniil Gentili 2019-06-02 11:34:19 +02:00
parent 5e6beafec6
commit ab6175575e
4 changed files with 26 additions and 11 deletions

View File

@ -15,6 +15,7 @@
* new APIfactory
* sendmessage with secret messages
* 2fa+++++
* improved callfork
Things to expect in the next releases:
Document async apis
optional max_id and min_id

2
docs

@ -1 +1 @@
Subproject commit ba08d57eedb6e134247a74e64b4acc721d5dfcbd
Subproject commit 68d3db083aac2eb162802645eb18c539550df5a6

View File

@ -568,8 +568,10 @@ trait ResponseHandler
if ($botAPI) {
$response = yield $this->MTProto_to_botAPI_async($response);
}
$this->datacenter->sockets[$datacenter]->outgoing_messages[$request_id]['promise']->resolve($response);
unset($this->datacenter->sockets[$datacenter]->outgoing_messages[$request_id]['promise']);
if (isset($this->datacenter->sockets[$datacenter]->outgoing_messages[$request_id]['promise'])) { // This should not happen but happens, should debug
$this->datacenter->sockets[$datacenter]->outgoing_messages[$request_id]['promise']->resolve($response);
unset($this->datacenter->sockets[$datacenter]->outgoing_messages[$request_id]['promise']);
}
}
)());
}

View File

@ -25,10 +25,10 @@ use Amp\Promise;
use Amp\Success;
use function Amp\Promise\all;
use function Amp\Promise\any;
use function Amp\Promise\some;
use function Amp\Promise\wait;
use function Amp\Promise\first;
use function Amp\Promise\some;
use function Amp\Promise\timeout;
use function Amp\Promise\wait;
/**
* Some tools.
@ -172,7 +172,7 @@ trait Tools
return unpack('d', \danog\MadelineProto\Magic::$BIG_ENDIAN ? strrev($value) : $value)[1];
}
public function wait($promise)
{
if ($promise instanceof \Generator) {
@ -247,18 +247,27 @@ trait Tools
return $promise;
}
public function callFork($promise, $actual = null)
public function callFork($promise, $actual = null, $file = '')
{
if ($actual) {
$promise = $actual;
} else {
$trace = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS, 1)[0];
$file = '';
if (isset($trace['file'])) {
$file .= basename($trace['file'], '.php');
}
if (isset($trace['line'])) {
$file .= ":{$trace['line']}";
}
}
if ($promise instanceof \Generator) {
$promise = new Coroutine($promise);
}
if ($promise instanceof Promise) {
$promise->onResolve(function ($e, $res) {
$promise->onResolve(function ($e, $res) use ($file) {
if ($e) {
$this->rethrow($e);
$this->rethrow($e, $file);
}
});
}
@ -268,10 +277,13 @@ trait Tools
{
Loop::defer([$this, 'callFork'], $promise);
}
public function rethrow($e)
public function rethrow($e, $file = '')
{
$logger = isset($this->logger) ? $this->logger : Logger::$default;
$logger->logger("Got the following exception within a forked strand, trying to rethrow");
if ($file) {
$file = " started @ $file";
}
$logger->logger("Got the following exception within a forked strand$file, trying to rethrow");
$logger->logger((string) $e);
Promise\rethrow(new Failure($e));
}