Try setting signal handler before passing control to loop

This commit is contained in:
Daniil Gentili 2020-08-27 18:04:55 +02:00
parent a81cd4c221
commit c4cf967198
Signed by: danog
GPG Key ID: 8C1BE3B34B230CA7
5 changed files with 8 additions and 10 deletions

View File

@ -71,8 +71,7 @@ class Postgres
while (yield $result->advance()) { while (yield $result->advance()) {
$row = $result->getCurrent(); $row = $result->getCurrent();
if ($row===false) if ($row===false) {
{
yield $connection->query(" yield $connection->query("
CREATE DATABASE {$db} CREATE DATABASE {$db}
OWNER {$user} OWNER {$user}
@ -92,7 +91,7 @@ class Postgres
END IF; END IF;
END; END;
$$ language 'plpgsql' $$ language 'plpgsql'
"); ");
$connection->close(); $connection->close();
} catch (\Throwable $e) { } catch (\Throwable $e) {
Logger::log($e->getMessage(), Logger::ERROR); Logger::log($e->getMessage(), Logger::ERROR);

View File

@ -9,7 +9,6 @@ use Amp\Sql\ResultSet;
use danog\MadelineProto\Logger; use danog\MadelineProto\Logger;
use function Amp\call; use function Amp\call;
class PostgresArray implements DbArray class PostgresArray implements DbArray
{ {
use ArrayCacheTrait; use ArrayCacheTrait;
@ -39,7 +38,8 @@ class PostgresArray implements DbArray
$this->setCache($index, $value); $this->setCache($index, $value);
$request = $this->request(" $request = $this->request(
"
INSERT INTO \"{$this->table}\" INSERT INTO \"{$this->table}\"
(key,value) (key,value)
VALUES (:index, :value) VALUES (:index, :value)
@ -79,7 +79,7 @@ class PostgresArray implements DbArray
private function prepareTable() private function prepareTable()
{ {
Logger::log("Creating/checking table {$this->table}", Logger::WARNING); Logger::log("Creating/checking table {$this->table}", Logger::WARNING);
yield $this->request(" yield $this->request("
CREATE TABLE IF NOT EXISTS \"{$this->table}\" CREATE TABLE IF NOT EXISTS \"{$this->table}\"
( (
@ -381,4 +381,4 @@ class PostgresArray implements DbArray
return $result; return $result;
}); });
} }
} }

View File

@ -23,8 +23,6 @@ use danog\Loop\ResumableSignalLoop;
use danog\MadelineProto\Loop\InternalLoop; use danog\MadelineProto\Loop\InternalLoop;
use danog\MadelineProto\MTProto; use danog\MadelineProto\MTProto;
use function Amp\delay;
/** /**
* Update feed loop. * Update feed loop.
* *

View File

@ -28,7 +28,6 @@ use danog\MadelineProto\Db\DbArray;
use danog\MadelineProto\Db\DbPropertiesFabric; use danog\MadelineProto\Db\DbPropertiesFabric;
use danog\MadelineProto\Db\DbPropertiesTrait; use danog\MadelineProto\Db\DbPropertiesTrait;
use danog\MadelineProto\Db\Mysql; use danog\MadelineProto\Db\Mysql;
use danog\MadelineProto\Db\Pgsql;
use danog\MadelineProto\Ipc\Server; use danog\MadelineProto\Ipc\Server;
use danog\MadelineProto\Loop\Generic\PeriodicLoopInternal; use danog\MadelineProto\Loop\Generic\PeriodicLoopInternal;
use danog\MadelineProto\Loop\Update\FeedLoop; use danog\MadelineProto\Loop\Update\FeedLoop;

View File

@ -262,6 +262,8 @@ class Magic
if (\defined(\SIGINT::class)) { if (\defined(\SIGINT::class)) {
//if (function_exists('pcntl_async_signals')) pcntl_async_signals(true); //if (function_exists('pcntl_async_signals')) pcntl_async_signals(true);
try { try {
\pcntl_signal(SIGINT, fn () => null);
\pcntl_signal(SIGINT, SIG_DFL);
Loop::unreference(Loop::onSignal(SIGINT, static function () { Loop::unreference(Loop::onSignal(SIGINT, static function () {
Logger::log('Got sigint', Logger::FATAL_ERROR); Logger::log('Got sigint', Logger::FATAL_ERROR);
Magic::shutdown(1); Magic::shutdown(1);