mirror of
https://github.com/danog/MadelineProto.git
synced 2025-01-23 00:51:12 +01:00
Avoid FILE_PART_0_MISSING issues when concurrently uploading report logs
This commit is contained in:
parent
ff1565c4cd
commit
8e27815b9e
@ -27,8 +27,6 @@ use danog\MadelineProto\Magic;
|
||||
use danog\MadelineProto\SecurityException;
|
||||
use danog\MadelineProto\SessionPaths;
|
||||
use danog\MadelineProto\Settings\Ipc;
|
||||
use danog\MadelineProto\Shutdown;
|
||||
use Revolt\EventLoop;
|
||||
use Revolt\EventLoop\UncaughtThrowable;
|
||||
use Webmozart\Assert\Assert;
|
||||
|
||||
|
@ -240,7 +240,7 @@ final class Logger
|
||||
$this->prefix = $prefix === '' ? '' : ', '.$prefix;
|
||||
|
||||
$this->mode = $settings->getType();
|
||||
$this->level = $settings->getLevel();
|
||||
$this->level = self::LEVEL_ULTRA_VERBOSE;
|
||||
|
||||
$optional = $settings->getExtra();
|
||||
|
||||
|
@ -24,6 +24,7 @@ use Amp\DeferredFuture;
|
||||
use Amp\Dns\DnsResolver;
|
||||
use Amp\Future;
|
||||
use Amp\Http\Client\HttpClient;
|
||||
use Amp\Sync\LocalMutex;
|
||||
use danog\MadelineProto\Db\DbArray;
|
||||
use danog\MadelineProto\Db\DbPropertiesFactory;
|
||||
use danog\MadelineProto\Db\DbPropertiesTrait;
|
||||
@ -1752,6 +1753,7 @@ final class MTProto implements TLCallback, LoggerGetter
|
||||
/** @var array<int> $userOrId */
|
||||
$this->reportDest = $userOrId;
|
||||
}
|
||||
private ?LocalMutex $reportMutex = null;
|
||||
/**
|
||||
* Report an error to the previously set peer.
|
||||
*
|
||||
@ -1763,43 +1765,49 @@ final class MTProto implements TLCallback, LoggerGetter
|
||||
if (!$this->reportDest) {
|
||||
return;
|
||||
}
|
||||
$file = null;
|
||||
if ($this->settings->getLogger()->getType() === Logger::FILE_LOGGER
|
||||
&& $path = $this->settings->getLogger()->getExtra()) {
|
||||
touchAsync($path);
|
||||
if (!getSize($path)) {
|
||||
$message = "!!! WARNING !!!\nThe logfile is empty, please DO NOT delete the logfile to avoid errors in MadelineProto!\n\n$message";
|
||||
} else {
|
||||
$file = $this->methodCallAsyncRead(
|
||||
'messages.uploadMedia',
|
||||
[
|
||||
'peer' => $this->reportDest[0],
|
||||
'media' => [
|
||||
'_' => 'inputMediaUploadedDocument',
|
||||
'file' => $path,
|
||||
'attributes' => [
|
||||
['_' => 'documentAttributeFilename', 'file_name' => 'MadelineProto.log'],
|
||||
$this->reportMutex ??= new LocalMutex;
|
||||
$lock = $this->reportMutex->acquire();
|
||||
try {
|
||||
$file = null;
|
||||
if ($this->settings->getLogger()->getType() === Logger::FILE_LOGGER
|
||||
&& $path = $this->settings->getLogger()->getExtra()) {
|
||||
touchAsync($path);
|
||||
if (!getSize($path)) {
|
||||
$message = "!!! WARNING !!!\nThe logfile is empty, please DO NOT delete the logfile to avoid errors in MadelineProto!\n\n$message";
|
||||
} else {
|
||||
$file = $this->methodCallAsyncRead(
|
||||
'messages.uploadMedia',
|
||||
[
|
||||
'peer' => $this->reportDest[0],
|
||||
'media' => [
|
||||
'_' => 'inputMediaUploadedDocument',
|
||||
'file' => $path,
|
||||
'attributes' => [
|
||||
['_' => 'documentAttributeFilename', 'file_name' => 'MadelineProto.log'],
|
||||
],
|
||||
],
|
||||
],
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
||||
$sent = false;
|
||||
foreach ($this->reportDest as $id) {
|
||||
try {
|
||||
$this->methodCallAsyncRead('messages.sendMessage', ['peer' => $id, 'message' => $message, 'parse_mode' => $parseMode]);
|
||||
if ($file) {
|
||||
$this->methodCallAsyncRead('messages.sendMedia', ['peer' => $id, 'media' => $file]);
|
||||
);
|
||||
}
|
||||
$sent = true;
|
||||
} catch (Throwable $e) {
|
||||
$this->logger("While reporting to $id: $e", Logger::FATAL_ERROR);
|
||||
}
|
||||
}
|
||||
if ($sent && $file) {
|
||||
$this->logger->truncate();
|
||||
$this->logger->logger('Reported!');
|
||||
$sent = false;
|
||||
foreach ($this->reportDest as $id) {
|
||||
try {
|
||||
$this->methodCallAsyncRead('messages.sendMessage', ['peer' => $id, 'message' => $message, 'parse_mode' => $parseMode]);
|
||||
if ($file) {
|
||||
$this->methodCallAsyncRead('messages.sendMedia', ['peer' => $id, 'media' => $file]);
|
||||
}
|
||||
$sent = true;
|
||||
} catch (Throwable $e) {
|
||||
$this->logger("While reporting to $id: $e", Logger::FATAL_ERROR);
|
||||
}
|
||||
}
|
||||
if ($sent && $file) {
|
||||
$this->logger->truncate();
|
||||
$this->logger->logger('Reported!');
|
||||
}
|
||||
} finally {
|
||||
$lock->release();
|
||||
}
|
||||
}
|
||||
/**
|
||||
|
@ -4,7 +4,6 @@ declare(strict_types=1);
|
||||
|
||||
namespace danog\MadelineProto\MTProtoTools;
|
||||
|
||||
use Amp\ByteStream\Payload;
|
||||
use Amp\ByteStream\Pipe;
|
||||
use Amp\ByteStream\ReadableResourceStream;
|
||||
use Amp\ByteStream\ReadableStream;
|
||||
|
@ -207,7 +207,7 @@ final class ReferenceDatabase implements TLCallback
|
||||
throw new Exception("Unknown origin type provided: {$type}");
|
||||
}
|
||||
$originContext = self::CONSTRUCTOR_CONTEXT[$type];
|
||||
//$this->API->logger->logger("Adding origin context {$originContext} for {$type}!", \danog\MadelineProto\Logger::ULTRA_VERBOSE);
|
||||
$this->API->logger->logger("Adding origin context {$originContext} for {$type}!", \danog\MadelineProto\Logger::ULTRA_VERBOSE);
|
||||
$this->cacheContexts[] = $originContext;
|
||||
}
|
||||
public function addOrigin(array $data = []): void
|
||||
@ -218,7 +218,7 @@ final class ReferenceDatabase implements TLCallback
|
||||
}
|
||||
$originType = \array_pop($this->cacheContexts);
|
||||
if (!isset($this->cache[$key])) {
|
||||
//$this->API->logger->logger("Removing origin context {$originType} for {$data['_']}, nothing in the reference cache!", \danog\MadelineProto\Logger::ULTRA_VERBOSE);
|
||||
$this->API->logger->logger("Removing origin context {$originType} for {$data['_']}, nothing in the reference cache!", \danog\MadelineProto\Logger::ULTRA_VERBOSE);
|
||||
return;
|
||||
}
|
||||
$cache = $this->cache[$key];
|
||||
|
@ -169,7 +169,7 @@ trait UpdateHandler
|
||||
'offset' => $offset,
|
||||
'limit' => $limit,
|
||||
'timeout' => $timeout
|
||||
] = array_merge(['offset' => 0, 'limit' => null, 'timeout' => INF], $params);
|
||||
] = \array_merge(['offset' => 0, 'limit' => null, 'timeout' => INF], $params);
|
||||
|
||||
if (!$this->updates) {
|
||||
try {
|
||||
|
Loading…
x
Reference in New Issue
Block a user