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 397F4805A4; Mon, 31 Oct 2022 16:13:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gnuweeb.org; s=default; t=1667232783; bh=uDCH87cfezPoTlHiZ7fSDPcvp24ofKy3jZunT9WobeU=; h=From:To:Cc:Subject:Date:From; b=IkwqfM495hZMoJ8MGDlTgKRNYbGAib8t/L5YLIA7WIU8E/oFgqulNjKpETb/NkwRJ hrZCF7vU9BjwjPiDdG4aM17ftvLXbWSPimrgWaYX+7ueafHhAfFsc1SLkoqPBQrVte 9o6sCsWnOi0tM/6ZpG3JfnC7d41lOAtDn1DAREieZ4F9v59fGJJtQCacMeokHvWbsN k4k0+yNUy8pXwJRzA16c14rpjo9Ie9dlWXgeNLG6GVWn7vn+expN1i5sXI75ppdzUv kjSww7lXRHs2IXxWfG6aRTIMJ0ZMFe2tirQ/v+09kQFZfn5lzrpyHkpM274sJKoToZ iPk/btc99wEqw== From: Ammar Faizi To: GNU/Weeb Mailing List Cc: Ammar Faizi , Muhammad Rizki , Alviro Iskandar Setiawan Subject: [PATCH RESEND v3 0/2] Automatic recovery from a MySQL restart Date: Mon, 31 Oct 2022 23:12:54 +0700 Message-Id: <20221031161256.199149-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 v2 -> v3: - Simplify try and except statement (comment from Muhammad Rizki). 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 | 29 +++++++++++++++++++++++++---- 2 files changed, 30 insertions(+), 4 deletions(-) base-commit: 6e94cf607287e5bc209e9c14c8156c7ad49455e3 -- Ammar Faizi