GNU/Weeb Mailing List <[email protected]>
 help / color / mirror / Atom feed
From: Ammar Faizi <[email protected]>
To: Alviro Iskandar Setiawan <[email protected]>
Cc: GNU/Weeb Mailing List <[email protected]>,
	Muhammad Rizki <[email protected]>
Subject: Re: [PATCH v1 2/2] daemon: telegram: Handle MySQL error
Date: Fri, 28 Oct 2022 23:29:10 +0700	[thread overview]
Message-ID: <[email protected]> (raw)
In-Reply-To: <[email protected]>

On 10/28/22 4:43 PM, Ammar Faizi wrote:
> On 10/28/22 4:40 PM, Alviro Iskandar Setiawan wrote:
>> On Fri, Oct 28, 2022 at 4:32 PM Ammar Faizi wrote:
>>> On 10/28/22 4:24 PM, Alviro Iskandar Setiawan wrote:
>>>> I think this reconnect() handling should be done in each DB method,
>>>> not here, otherwise we'll potentially have a half-inserted data and
>>>> may get it wrong.
>>>
>>> By using a transaction, such a situation cannot happen. It already
>>> fulfills the ACID requirements. But I doubt we've fully handled that
>>> properly. This needs extra code review, especially in that critical
>>> section.
>>
>> Turning on autocommit for everything is usually a hint that you did
>> ACID wrong, maybe not you, but Rizki.
> 
> Maybe, that's why I said "I doubt". But I don't have time to review it
> for now, will do that later.

I've just checked it. And yes, we have haven't fulfilled the ACID
requirements here. While the following __send_mail method is holding the
mutex while it's operating, it doesn't perform a rollback() operation if
the subsequent SQL queries fail.

So yes, having autocommit = True for everything is absolutely the wrong
thing to do. We have to fix this issue at some point.

It's currently working fine, only the corner case, that's when the MySQL
hits error in the middle of __send_mail function.

I believe there are more issues like this somewhere else. But this is
the most hot path to get spotted. We also have to teach Rizki about this
so he can fix it himself.

# @__must_hold(self.mutexes.send_to_tg)
async def __send_mail(self, url, mail, tg_chat_id):
	email_msg_id = utils.get_email_msg_id(mail)
	if not email_msg_id:
		#
		# It doesn't have a Message-Id.
		# A malformed email. Skip!
		#
		return False

	email_id = self.__mail_id_from_db(email_msg_id,
						tg_chat_id)
	if not email_id:
		#
		# Email has already been sent to Telegram.
		# Skip!
		#
		return False

	text, files, is_patch = utils.create_template(mail, Platform.TELEGRAM)
	reply_to = self.get_reply(mail, tg_chat_id)
	url = str(re.sub(r"/raw$", "", url))

	if is_patch:
		m: "Message" = await self.client.send_patch_email(
			mail, tg_chat_id, text, reply_to, url
		)
	else:
		text = "#ml\n" + text
		m: "Message" = await self.client.send_text_email(
			tg_chat_id, text,reply_to, url
		)

	self.db.save_telegram_mail(email_id, m.chat.id, m.id)
	for d, f in files:
		await m.reply_document(f"{d}/{f}", file_name=f)
		await asyncio.sleep(1)

	utils.remove_patch(files)

	return True

-- 
Ammar Faizi


  reply	other threads:[~2022-10-28 16:29 UTC|newest]

Thread overview: 42+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-10-27 15:08 [PATCH v1 0/2] Automatic recovery from a MySQL restart Ammar Faizi
2022-10-27 15:08 ` [PATCH v1 1/2] daemon: telegram: db: Allow the caller to reconnect Ammar Faizi
2022-10-27 16:52   ` Muhammad Rizki
2022-10-27 16:54     ` Muhammad Rizki
2022-10-28  5:48       ` Ammar Faizi
2022-10-27 15:08 ` [PATCH v1 2/2] daemon: telegram: Handle MySQL error Ammar Faizi
2022-10-28  9:21   ` Alviro Iskandar Setiawan
2022-10-28  9:28     ` Ammar Faizi
2022-10-28  9:24   ` Alviro Iskandar Setiawan
2022-10-28  9:32     ` Ammar Faizi
2022-10-28  9:40       ` Alviro Iskandar Setiawan
2022-10-28  9:43         ` Ammar Faizi
2022-10-28 16:29           ` Ammar Faizi [this message]
2022-10-28 16:46             ` Alviro Iskandar Setiawan
2022-10-28 16:54               ` Ammar Faizi
2022-10-28 18:10               ` Muhammad Rizki
2022-10-28 18:26                 ` Alviro Iskandar Setiawan
2022-10-28 18:52                   ` Muhammad Rizki
2022-10-28 19:08                     ` Alviro Iskandar Setiawan
2022-10-28 19:15                       ` Muhammad Rizki
2022-10-28 19:29                         ` Alviro Iskandar Setiawan
2022-10-28 19:34                           ` Ammar Faizi
2022-10-28 19:36                             ` Ammar Faizi
2022-10-28 19:38                               ` Ammar Faizi
2022-10-28 19:44                                 ` Muhammad Rizki
2022-10-28 19:39                           ` Muhammad Rizki
2022-10-28 19:44                             ` Alviro Iskandar Setiawan
2022-10-28 19:46                               ` Muhammad Rizki
2022-10-28 19:53                                 ` Alviro Iskandar Setiawan
2022-10-28 19:16                     ` Ammar Faizi
2022-10-28 19:19                       ` Muhammad Rizki
2022-10-28 19:19                         ` Ammar Faizi
2022-10-28 19:22                           ` Muhammad Rizki
2022-10-28 19:33                             ` Ammar Faizi
2022-10-28 19:38                               ` Muhammad Rizki
2022-10-28 17:02             ` Muhammad Rizki
2022-10-28 17:19               ` Ammar Faizi
2022-10-28 18:15                 ` Muhammad Rizki
2022-10-28 18:18                   ` Muhammad Rizki
2022-10-28 19:49                     ` Ammar Faizi
2022-10-28 19:55                       ` Muhammad Rizki
2022-10-28 19:46                   ` Ammar Faizi

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    [email protected] \
    [email protected] \
    [email protected] \
    [email protected] \
    [email protected] \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox