Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1qLyxk-0017zY-4e for pgsql-hackers@arkaria.postgresql.org; Wed, 19 Jul 2023 04:38:56 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.94.2) (envelope-from ) id 1qLyxi-00HX84-3f for pgsql-hackers@arkaria.postgresql.org; Wed, 19 Jul 2023 04:38:54 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1qLyxh-00HX7t-QP for pgsql-hackers@lists.postgresql.org; Wed, 19 Jul 2023 04:38:53 +0000 Received: from mail-ua1-x92b.google.com ([2607:f8b0:4864:20::92b]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.94.2) (envelope-from ) id 1qLyxe-000FXM-Tq for pgsql-hackers@lists.postgresql.org; Wed, 19 Jul 2023 04:38:52 +0000 Received: by mail-ua1-x92b.google.com with SMTP id a1e0cc1a2514c-794b8fe8cc4so289776241.0 for ; Tue, 18 Jul 2023 21:38:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1689741530; x=1692333530; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=NbRMrE7uVXprR1Kj+MCcZNKypGWTz6BgmFtqlNhykpQ=; b=BW1BRKjuG7AZXS3hEaxeD/fdak4wY5lwhI9bN3ABH6WWaKOIq9HvyhXCI2ubqzoDWl Xgt8edyzFkyJRXMX+jmAkGWe085C/ZEolqlmMEj4bT9OfgH0YpkcpzT7/5Rm3tUsNFoY P1NjOyiJB9vdwl+GYvUcHBrw/IWi5z5swBU5PTl7A6XDvAwx4uNF0pl0KeVrIn15EaD7 iV9oLJMHVC+RsPz6I4R/m5oRKadzmujJljmzYlXaWJz0RBqAFiMW44wRZZ5W2XoQXS7N sLB6NmhQ1WpgesTv7am/NhlAjAwW3vb7voQR7S1vOH/4XTe0pFXU9dMNyvc6NVRHq9pN wfQA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1689741530; x=1692333530; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=NbRMrE7uVXprR1Kj+MCcZNKypGWTz6BgmFtqlNhykpQ=; b=GRwdfx3/itJ1hTze7CBEooLylHSViIsXahJco7JIUXzrmPlB1cv7Zqid0EcKW+7pQ5 8iObBCdjcoDdhDtDPPsyHG5v96wY5t26zroeqEUCYMMyIf44vBf29HpprNeMs1ZwHxhU COhx6EEluhibJ+cnpPEteoaQuAikoZtv0dVcHzXOckx/O6QqeiH/CfxGHpy1cY0A1bxU 0rb5T3mu+UHbD4giCyHNl+Z+y8ftmQZBhcv/3Og6kPq0o1RWPPxsHcExGzBtb9N21MGC 0Z/dYHl7772AmdzJLQS64zkyLN+bTCuUbCbwE9bESyJfkoh7Z3MWx+X/m00DxNtRe+Be LqvQ== X-Gm-Message-State: ABy/qLYedhiAaR/2Je16yLkRVFuoEfibweWiLmhKzncIdgeiYHt/Zk63 Qxx3AfXJ8E4TEylxk+FQbk/J/2AdpKSu8N7570o= X-Google-Smtp-Source: APBJJlFJEdMil5yfixvmFj04eG/Wz69W97BI9izslbCpBXOjfoVpV/hWijSXAUmRkcsXXZCsZ65koustqTJ6kzp5Wk8= X-Received: by 2002:a67:c91a:0:b0:443:6595:a575 with SMTP id w26-20020a67c91a000000b004436595a575mr255737vsk.16.1689741529901; Tue, 18 Jul 2023 21:38:49 -0700 (PDT) MIME-Version: 1.0 References: <20230717142452.74yml7mfqkypfixp@alvherre.pgsql> In-Reply-To: From: Ashutosh Bapat Date: Wed, 19 Jul 2023 10:08:38 +0530 Message-ID: Subject: Re: logicalrep_message_type throws an error To: Amit Kapila Cc: Masahiko Sawada , Alvaro Herrera , Euler Taveira , pgsql-hackers@lists.postgresql.org Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On Wed, Jul 19, 2023 at 9:01=E2=80=AFAM Amit Kapila wrote: > > On Tue, Jul 18, 2023 at 10:27=E2=80=AFAM Masahiko Sawada wrote: > > > > On Tue, Jul 18, 2023 at 12:15=E2=80=AFPM Amit Kapila wrote: > > > > > > On Mon, Jul 17, 2023 at 7:54=E2=80=AFPM Alvaro Herrera wrote: > > > > > > > > > > I have tried to check whether we have such usage in any other error > > > callbacks. Though I haven't scrutinized each and every error callback= , > > > I found a few of them where an error can be raised. For example, > > > > > > rm_redo_error_callback()->initStringInfo() > > > CopyFromErrorCallback()->limit_printout_length() > > > shared_buffer_write_error_callback()->relpathperm()->relpathbackend()= ->GetRelationPath()->psprintf() > > > > > > > Let's > > > > just do the thing in the original patch you submitted, to ensure al= l > > > > these strings are compile-time constants; that's likely the most ro= bust. > > > > > > > > Or can we use snprintf() writing "??? (%d)" to a fixed length char[8 + > > 11] allocated on the stack instead? > > > > In the above size calculation, shouldn't it be 7 + 11 where 7 is for > (3 (???) + 1 for space + 2 for () + 1 for terminating null char) and > 11 is for %d? BTW, this avoids dynamic allocation of the err string in > logicalrep_message_type() but we can't return a locally allocated > string, so do you think we should change the prototype of the function > to get this as an argument and then use it both for valid and invalid > cases? There are other places in the code which do something similar by using statically allocated buffers like static char xya[SIZE]. We could do that here. The caller may decide whether to pstrdup this buffer further or just use it one time e.g. as an elog or printf argument. As I said before, we should not even print message type in the error context because it's unknown. Repeating that twice is useless. That will need some changes to apply_error_callback() though. But I am fine with "???" as well. --=20 Best Wishes, Ashutosh Bapat