Skip to content

Commit b40865e

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 463ed88 commit b40865e

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

src/backend/commands/subscriptioncmds.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -507,6 +507,7 @@ AlterSubscription_refresh(Subscription *sub, bool copy_data)
507507
List *subrel_states;
508508
Oid *subrel_local_oids;
509509
Oid *pubrel_local_oids;
510+
WalReceiverConn *wrconn;
510511
ListCell *lc;
511512
int off;
512513

@@ -821,7 +822,7 @@ DropSubscription(DropSubscriptionStmt *stmt, bool isTopLevel)
821822
char originname[NAMEDATALEN];
822823
char *err = NULL;
823824
RepOriginId originid;
824-
WalReceiverConn *wrconn = NULL;
825+
WalReceiverConn *wrconn;
825826
StringInfoData cmd;
826827

827828
/*

0 commit comments

Comments
 (0)