From ab6175575e241f25813d504f19a2917c3939d846 Mon Sep 17 00:00:00 2001 From: Daniil Gentili Date: Sun, 2 Jun 2019 11:34:19 +0200 Subject: [PATCH] More logs and hotfix --- CHANGELOG.md | 1 + docs | 2 +- .../MTProtoTools/ResponseHandler.php | 6 ++-- src/danog/MadelineProto/Tools.php | 28 +++++++++++++------ 4 files changed, 26 insertions(+), 11 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index da7f5287..dc3aa248 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/docs b/docs index ba08d57e..68d3db08 160000 --- a/docs +++ b/docs @@ -1 +1 @@ -Subproject commit ba08d57eedb6e134247a74e64b4acc721d5dfcbd +Subproject commit 68d3db083aac2eb162802645eb18c539550df5a6 diff --git a/src/danog/MadelineProto/MTProtoTools/ResponseHandler.php b/src/danog/MadelineProto/MTProtoTools/ResponseHandler.php index d3023980..1f06beb1 100644 --- a/src/danog/MadelineProto/MTProtoTools/ResponseHandler.php +++ b/src/danog/MadelineProto/MTProtoTools/ResponseHandler.php @@ -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']); + } } )()); } diff --git a/src/danog/MadelineProto/Tools.php b/src/danog/MadelineProto/Tools.php index 47f7c6ea..f91f81d3 100644 --- a/src/danog/MadelineProto/Tools.php +++ b/src/danog/MadelineProto/Tools.php @@ -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)); }