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 mail-lj1-f172.google.com (mail-lj1-f172.google.com [209.85.208.172]) by gnuweeb.org (Postfix) with ESMTPSA id 48CF8804FD for ; Fri, 28 Oct 2022 19:09:01 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gnuweeb.org; s=default; t=1666984141; bh=dZZKaoKFHr6/ssZKZK6Yy3pxmtarLJExXTsf7zDsoyg=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=cRR6BcpLbCGMLlBRo2xE389YrZIbtQyrCcA8MBVDqA4ZAlJ08FdSudZ47ZHnEz94t o1ApeD5ihNUC4iJLYpdkKpvVCM80w7kdHd8uAuj1tZc8PskBzInoWOg7MPw7evdhZy XUGCZcqx0hO5rdKMdOuXE2x+deSi751UHIElUojZqqGeFuLCta+0w2cfIdp5JS1xwV aTJQhy4FNDwv2RL9YJlMU9Drk4fX7GUYYTxriwzny2bdZPlAwwsgEJ4Ugscn/L4A0f HehZAsB6rv5mrqNoQGO9UaiwjScdoHI/eAFUHvd6v0oJdaSx6CS2BaoYOXb/TlK4le 3U1mjqU19SkpQ== Received: by mail-lj1-f172.google.com with SMTP id z24so9524585ljn.4 for ; Fri, 28 Oct 2022 12:09:01 -0700 (PDT) X-Gm-Message-State: ACrzQf1Q5sSXxA/eLUe8EJOK8g40Xx0EqBrMjJH1EmTW99yBsCNRzDDi wgTZcCGeCFVJb4RblBpJB034J3jc6gp1NvYjhTI= X-Google-Smtp-Source: AMsMyM6/4WFzLloRsCrHLFF/mDyVEaXh7WVOMHwXrPJat6MF8ZuuC/31CKiZvUnqC90RDqI0ww+JvvOmOWTVCm4rECI= X-Received: by 2002:a2e:a587:0:b0:26f:eb13:514 with SMTP id m7-20020a2ea587000000b0026feb130514mr372819ljp.174.1666984139368; Fri, 28 Oct 2022 12:08:59 -0700 (PDT) MIME-Version: 1.0 References: <20221027150823.601914-1-ammarfaizi2@gnuweeb.org> <20221027150823.601914-3-ammarfaizi2@gnuweeb.org> <1d500d37-b11b-75fd-38e5-d7f8e0a9b1d4@gnuweeb.org> <3a79a587-ddee-9e25-2ac5-b573938b44a9@gnuweeb.org> <043f55c3-67d8-9130-aca4-73c59926d2af@gnuweeb.org> <63aa1b63-f7e2-8da3-b16d-0c7e1045d697@gnuweeb.org> <9ecfe8ab-fa5a-d01a-0b68-bc639f14888f@gnuweeb.org> In-Reply-To: <9ecfe8ab-fa5a-d01a-0b68-bc639f14888f@gnuweeb.org> From: Alviro Iskandar Setiawan Date: Sat, 29 Oct 2022 02:08:48 +0700 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH v1 2/2] daemon: telegram: Handle MySQL error To: Muhammad Rizki Cc: Ammar Faizi , "GNU/Weeb Mailing List" Content-Type: text/plain; charset="UTF-8" List-Id: On Sat, Oct 29, 2022 at 1:52 AM Muhammad Rizki wrote: > It will throw an exception before executing the remove_patch(), but, the > problem is not "if m.reply_document() throw an exception", but the files > variable from the utils.create_template() is the problem if throw an > exception, I think it will be throw a local variable error. "if m.reply_document() throws an exception" is a REAL PROBLEM. - m.reply_document() performs a network I/O. Therefore it may FAIL. - send_patch_email() performs a network I/O. Therefore it may FAIL. - send_text_email() performs a network I/O. Therefore it may FAIL. - MySQL queries perform a network I/O. Therefore they may FAIL. - whatever... If one of them fails, remove_patch() *is not executed*. > Here is my improved remove_patch(): > > > def remove_patch( > tmp: Union[str, list] = None, > platform: Platform = Platform.TELEGRAM > ): > if isinstance(tmp, str): > return shutil.rmtree(tmp) > > # check if the tmp is None or an empty list or empty str > # if they are empty or None then remove using glob UNIX > # style path which is if empty will not throw an error > if not bool(tmp): > platform = platform.TELEGRAM.value > store_dir = os.getenv("STORAGE_DIR", "storage") > for d in glob.glob(f"{platform}/{store_dir}/*/"): > shutil.rmtree(d) > return This is insane. That listener is running asynchronously, and you delete all temporary files without holding any mutex. At that time, another async job *may still be using* the files you batch-delete in this code.