Fixes
This commit is contained in:
parent
bd07a2b4b9
commit
7d29bd84bc
@ -91,6 +91,13 @@ class API extends InternalDoc
|
||||
*/
|
||||
private $wrapper;
|
||||
|
||||
/**
|
||||
* Global session unlock callback
|
||||
*
|
||||
* @var callback
|
||||
*/
|
||||
private $unlock;
|
||||
|
||||
|
||||
/**
|
||||
* Magic constructor function.
|
||||
@ -127,7 +134,8 @@ class API extends InternalDoc
|
||||
{
|
||||
Logger::constructorFromSettings($settings);
|
||||
$this->session = $session = Tools::absolute($session);
|
||||
if ($unserialized = yield from Serialization::legacyUnserialize($session)) {
|
||||
[$unserialized, $this->unlock] = yield from Serialization::legacyUnserialize($session);
|
||||
if ($unserialized) {
|
||||
$unserialized->storage = $unserialized->storage ?? [];
|
||||
$unserialized->session = $session;
|
||||
APIWrapper::link($this, $unserialized);
|
||||
@ -185,6 +193,7 @@ class API extends InternalDoc
|
||||
}
|
||||
$this->destructing = true;
|
||||
Tools::wait($this->wrapper->serialize());
|
||||
if ($this->unlock) ($this->unlock)();
|
||||
} else {
|
||||
$this->logger->logger('Shutting down MadelineProto (old deserialized instance of API)');
|
||||
}
|
||||
|
@ -161,7 +161,7 @@ final class APIWrapper
|
||||
}
|
||||
|
||||
/**
|
||||
* Serialie session.
|
||||
* Serialize session.
|
||||
*
|
||||
* @return Promise
|
||||
*/
|
||||
|
@ -68,11 +68,11 @@ class Serialization
|
||||
Loop::unreference($warningId);
|
||||
});
|
||||
Loop::unreference($warningId);
|
||||
$unlock = yield Tools::flock($realpaths['session_lockfile'], LOCK_EX, 1);
|
||||
$unlockGlobal = yield Tools::flock($realpaths['session_lockfile'], LOCK_EX, 1);
|
||||
Loop::cancel($warningId);
|
||||
Shutdown::addCallback(static function () use ($unlock) {
|
||||
$tempId = Shutdown::addCallback($unlockGlobal = static function () use ($unlockGlobal) {
|
||||
Logger::log("Unlocking exclusive session lock!");
|
||||
$unlock();
|
||||
$unlockGlobal();
|
||||
Logger::log("Unlocked exclusive session lock!");
|
||||
});
|
||||
Logger::log("Got exclusive session lock!");
|
||||
@ -146,7 +146,8 @@ class Serialization
|
||||
if ($unserialized === false) {
|
||||
throw new Exception(\danog\MadelineProto\Lang::$current_lang['deserialization_error']);
|
||||
}
|
||||
return $unserialized;
|
||||
Shutdown::removeCallback($tempId);
|
||||
return [$unserialized, $unlockGlobal];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user