Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 4e8c0f1

Browse files
committed
AlterSubscription_refresh: avoid stomping on global variable
This patch replaces use of the global "wrconn" variable 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. Abusing it this way is known to cause trouble if an apply worker manages to do a subscription refresh, such as reported by Jeremy Finzel and diagnosed by Andres Freund back in November 2020, at https://www.postgresql.org/message-id/20201111215820.qihhrz7fayu6myfi@alap3.anarazel.de Backpatch to 10. In branch master, also move the connection establishment to occur outside the PG_TRY block; this way we can remove a test for NULL in PG_FINALLY, and it also makes the code more consistent with similar code in the same file. Author: Peter Smith <peter.b.smith@fujitsu.com> Reviewed-by: Bharath Rupireddy <bharath.rupireddyforpostgres@gmail.com> Reviewed-by: Japin Li <japinli@hotmail.com> Discussion: https://postgr.es/m/CAHut+Pu7Jv9L2BOEx_Z0UtJxfDevQSAUW2mJqWU+CtmDrEZVAg@mail.gmail.com
1 parent 8b82de0 commit 4e8c0f1

File tree

1 file changed

+9
-9
lines changed

1 file changed

+9
-9
lines changed

src/backend/commands/subscriptioncmds.c

+9-9
Original file line numberDiff line numberDiff line change
@@ -556,18 +556,19 @@ AlterSubscription_refresh(Subscription *sub, bool copy_data)
556556
char state;
557557
} SubRemoveRels;
558558
SubRemoveRels *sub_remove_rels;
559+
WalReceiverConn *wrconn;
559560

560561
/* Load the library providing us libpq calls. */
561562
load_file("libpqwalreceiver", false);
562563

564+
/* Try to connect to the publisher. */
565+
wrconn = walrcv_connect(sub->conninfo, true, sub->name, &err);
566+
if (!wrconn)
567+
ereport(ERROR,
568+
(errmsg("could not connect to the publisher: %s", err)));
569+
563570
PG_TRY();
564571
{
565-
/* Try to connect to the publisher. */
566-
wrconn = walrcv_connect(sub->conninfo, true, sub->name, &err);
567-
if (!wrconn)
568-
ereport(ERROR,
569-
(errmsg("could not connect to the publisher: %s", err)));
570-
571572
/* Get the table list from publisher. */
572573
pubrel_names = fetch_table_list(wrconn, sub->publications);
573574

@@ -737,8 +738,7 @@ AlterSubscription_refresh(Subscription *sub, bool copy_data)
737738
}
738739
PG_FINALLY();
739740
{
740-
if (wrconn)
741-
walrcv_disconnect(wrconn);
741+
walrcv_disconnect(wrconn);
742742
}
743743
PG_END_TRY();
744744

@@ -1062,7 +1062,7 @@ DropSubscription(DropSubscriptionStmt *stmt, bool isTopLevel)
10621062
ListCell *lc;
10631063
char originname[NAMEDATALEN];
10641064
char *err = NULL;
1065-
WalReceiverConn *wrconn = NULL;
1065+
WalReceiverConn *wrconn;
10661066
Form_pg_subscription form;
10671067
List *rstates;
10681068

0 commit comments

Comments
 (0)