Re: AlterSubscription_refresh "wrconn" wrong variable?

From: Bharath Rupireddy <bharath(dot)rupireddyforpostgres(at)gmail(dot)com>
To: Peter Smith <smithpb2250(at)gmail(dot)com>
Cc: Japin Li <japinli(at)hotmail(dot)com>, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Re: AlterSubscription_refresh "wrconn" wrong variable?
Date: 2021-05-06 10:09:53
Message-ID: CALj2ACXtDxB9zaMmjhSFq6kh83EgVZAJj2w0+=qSaQ7PtXywVg@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On Thu, May 6, 2021 at 3:00 PM Peter Smith <smithpb2250(at)gmail(dot)com> wrote:
>
> On Thu, May 6, 2021 at 7:18 PM Japin Li <japinli(at)hotmail(dot)com> wrote:
> >
> >
> > On Thu, 06 May 2021 at 17:08, Peter Smith <smithpb2250(at)gmail(dot)com> wrote:
> > > On Wed, May 5, 2021 at 12:35 PM Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> wrote:
> > >>
> > >> Peter Smith <smithpb2250(at)gmail(dot)com> writes:
> > >> > This patch replaces the global "wrconn" in AlterSubscription_refresh with a local variable of the same name, making it consistent with other functions in subscriptioncmds.c (e.g. DropSubscription).
> > >> > The global wrconn is only meant to be used for logical apply/tablesync worker.
> > >> > Using the global/incorrect wrconn in AlterSubscription_refresh doesn't normally cause any problems, but harm is still posslble if the apply worker ever manages to do a subscription refresh. e.g. see [1]
> > >>
> > >> Hm. I would actually place the blame for this on whoever thought
> > >> it was okay to name a global variable something as generic as
> > >> "wrconn". Let's rename that while we're at it, say to something
> > >> like "tablesync_wrconn" (feel free to bikeshed).
> > >
> > > PSA v3 of the patch. Same as before, but now also renames the global
> > > variable from "wrconn" to "lrep_worker_wrconn".
> > >
> >
> > Thanks for updating patch. I'm confused why we move the walrcv_connect() out of
> > PG_TRY() block?
> > + /* Try to connect to the publisher. */
> > + wrconn = walrcv_connect(sub->conninfo, true, sub->name, &err);
> > + if (!wrconn)
> > + ereport(ERROR,
> > + (errmsg("could not connect to the publisher: %s", err)));
> > +
> > PG_TRY();
> > {
> > - /* Try to connect to the publisher. */
> > - wrconn = walrcv_connect(sub->conninfo, true, sub->name, &err);
> > - if (!wrconn)
> > - ereport(ERROR,
> > - (errmsg("could not connect to the publisher: %s", err)));
> > -
> > /* Get the table list from publisher. */
> > pubrel_names = fetch_table_list(wrconn, sub->publications);
>
> Thanks for your review. Reason for moving that out of the PG_TRY are:
>
> a) It makes code now consistent with other functions using wrconn. See
> CreateSubscription, DropSubscription etc
>
> b) It means don't need the wrconn NULL check anymore in the PG_FINALLY
> so it simplifies the disconnect.

And even if any error occurs after the connection is established and
while libpqrcv_PQexec is being done in libpqrcv_connect, we reach
PG_FINALLY() block to disconnect the connection, so no connection leak
can occur.

Patch looks good to me except for the comments in the commit message:
1) it crosses 80 char limit 2) a typo : "posslble"

Please add it to the current commitfest if not done already so that we
don't lose track of it and the patch gets a chance to be tested.

With Regards,
Bharath Rupireddy.
EnterpriseDB: http://www.enterprisedb.com

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Dagfinn Ilmari Mannsåker 2021-05-06 10:13:28 Re: Why do we have perl and sed versions of Gen_dummy_probes?
Previous Message Andres Freund 2021-05-06 09:50:38 Re: WIP: WAL prefetch (another approach)