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.184]) by gnuweeb.org (Postfix) with ESMTPSA id 9E77C7E31F; Sat, 24 Dec 2022 22:00:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gnuweeb.org; s=default; t=1671919217; bh=oVCqHOfg5rZtMeC0ScaEbUTN8cez+qiedVWPdG2WYOg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=YxqlIioi4qY7PUwuDDG543Taxo54RVH9iSkWt9hDdQvcUY5aqedmYtlHv5npw7TEt a3D3xfg0JpQoM2DR+1dPgDGnHZ2WmGPrprfghSrXJHY38yd8JzLTSm3g1NUe+tXnH3 gvSe5vPtTKljblJoohtsV2sqLJmcqEe7Zoxq7wSFdxXH3DzJcdZSrR0CCgzSmrWFdr XHcuvNUVEZkkx9fN+eaIn669NGDkGLXd2zpLEyo9/Qc0WzOQBFJ8SIaqFoiuUl8T1x 1KTQO9kzCcKemiBd6HadNykFWg7s1zUqTjYRc06lORB8aD2FYVnH4FMN5zkl8vu8R/ E8l439A7c5A9A== From: Ammar Faizi To: GNU/Weeb Mailing List Cc: Ammar Faizi , Muhammad Rizki , Alviro Iskandar Setiawan Subject: [PATCH v1 1/2] telegram: listener: Fix missing MySQL error recovery function Date: Sun, 25 Dec 2022 05:00:07 +0700 Message-Id: <20221224220008.258335-2-ammarfaizi2@gnuweeb.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20221224220008.258335-1-ammarfaizi2@gnuweeb.org> References: <20221224220008.258335-1-ammarfaizi2@gnuweeb.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit List-Id: From: Ammar Faizi When I restarted the MySQL server, the program kept looping in the report function, reporting the same error: "Lost connection to MySQL server during query" This happened because commit ce17f3e8016c ("telegram: Implement the log message for catching errors") added an error logging using a 'try and except' statement. This statement effectively kills the MySQL recovery function that the caller ('__run' function) provides. Create a new function wrapper, report_err(). Also, make sure the MySQL error recovery function is called. Fixes: ce17f3e8016c ("telegram: Implement the log message for catching errors") Signed-off-by: Ammar Faizi --- daemon/telegram/mailer/listener.py | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/daemon/telegram/mailer/listener.py b/daemon/telegram/mailer/listener.py index 5a182d0..044de6a 100644 --- a/daemon/telegram/mailer/listener.py +++ b/daemon/telegram/mailer/listener.py @@ -61,19 +61,23 @@ class Bot(): self.db.ping(reconnect=True, attempts=reconnect_attempts, delay=delay_in_secs) + async def report_err(caption): + if not caption: + caption = "No lore URL" + exc_str = utils.catch_err() + self.logger.warning(exc_str) + await self.client.send_log_file(caption) async def __run(self): self.logger.info("Running...") + url = None try: for url in self.db.get_atom_urls(): await self.__handle_atom_url(url) except (OperationalError, DatabaseError) as e: await self.handle_db_error(e) except: - exc_str = utils.catch_err() - self.logger.warning(exc_str) - capt = "Unknown raw lore URL, see full details in the log file." - await self.client.send_log_file(capt) + await self.report_err(url) if not self.isRunnerFixed: self.isRunnerFixed = True @@ -89,13 +93,8 @@ class Bot(): async def __handle_atom_url(self, url): urls = await self.scraper.get_new_threads_urls(url) for url in urls: - try: - mail = await self.scraper.get_email_from_url(url) - await self.__handle_mail(url, mail) - except: - exc_str = utils.catch_err() - self.logger.warning(exc_str) - await self.client.send_log_file(url) + mail = await self.scraper.get_email_from_url(url) + await self.__handle_mail(url, mail) async def __handle_mail(self, url, mail): -- Ammar Faizi