From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on gnuweeb.org X-Spam-Level: X-Spam-Status: No, score=-0.8 required=5.0 tests=ALL_TRUSTED,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,NO_DNS_FOR_FROM,URIBL_BLOCKED autolearn=no autolearn_force=no version=3.4.6 Received: from localhost.localdomain (unknown [182.253.183.90]) by gnuweeb.org (Postfix) with ESMTPSA id C81C480E88; Sun, 30 Oct 2022 05:49:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gnuweeb.org; s=default; t=1667108979; bh=5AwXDEQMnZdNiTpIcLUKfVoHpPBi+SJ30XCREKw6ZqI=; h=From:To:Cc:Subject:Date:From; b=ODxHKYhb+q/RO+U56DV03CTqZDslG12vtHnYpDQRegVGw9YeJffSEA/xZdQ6Tm1vS qNWlwzfcTvhInXrBYPjWp+o9Z9cgDAPV7+5rTwfKwBGtl5iMZUx25HUU3W3stC614p nop05Gc1fe8JxWVCCRYbC/IKKVbXBZQuSKRt7szqVac00Sv8RGqilrtkGIW9M2VnGG T+XmTyyINISUV+KclX4AVODMLAqqcL85ebjsWOQXnTEEVJYqKu299xnCMFKp11tDsc Jw0TzeNvAvetkLQD3YlIjodnQAGZsWWygeT+iC9e9k+CPbdSfHrSD2WTQqiUOXcbiP 8DI5e8LjqRlHw== From: Ammar Faizi To: GNU/Weeb Mailing List Cc: Ammar Faizi , Muhammad Rizki , Alviro Iskandar Setiawan Subject: [PATCH v2 0/2] Automatic recovery from a MySQL restart Date: Sun, 30 Oct 2022 12:49:28 +0700 Message-Id: <20221030054930.573374-1-ammarfaizi2@gnuweeb.org> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit List-Id: Hi, This series adds a mechanism for the daemon to recover from a MySQL restart event. Currently, the daemon is totally unusable when the MySQL server is restarted. It's spinning in a loop with the following error: mysql.connector.errors.OperationalError: 2013 (HY000): Lost connection to MySQL server during query When it happens, the only way to fix the situation is: restart the daemon manually, which is obviously not productive. Create a mechanism in the class DB to allow the caller to reconnect. Handle MySQL error in the main daemon loop path. Do reconnect to the database if such an error happens. This way, the daemon can automatically recover from the MySQL server restart without having the user restart the daemon. There are two patches in this series: - Patch 1 is a preparation patch to create a recover mechanism. - Patch 2 is to implement the recover mechanism in the main daemon loop path. ## Changelog v1 -> v2: - Use conn.ping(reconnect=True) instead of creating a new MySQL connection object (comment from Muhammad Rizki). Signed-off-by: Ammar Faizi --- Ammar Faizi (2): daemon: telegram: db: Allow the caller to reconnect daemon: telegram: Handle MySQL error daemon/telegram/database/core.py | 5 +++++ daemon/telegram/mailer/listener.py | 31 ++++++++++++++++++++++++++---- 2 files changed, 32 insertions(+), 4 deletions(-) base-commit: 6e94cf607287e5bc209e9c14c8156c7ad49455e3 -- Ammar Faizi