Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit4e8c0f1

Browse files
committed
AlterSubscription_refresh: avoid stomping on global variable
This patch replaces use of the global "wrconn" variable inAlterSubscription_refresh with a local variable of the same name, makingit 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 workermanages to do a subscription refresh, such as reported by Jeremy Finzeland diagnosed by Andres Freund back in November 2020, athttps://www.postgresql.org/message-id/20201111215820.qihhrz7fayu6myfi@alap3.anarazel.deBackpatch to 10. In branch master, also move the connection establishmentto occur outside the PG_TRY block; this way we can remove a test for NULL inPG_FINALLY, and it also makes the code more consistent with similar code inthe 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 parent8b82de0 commit4e8c0f1

File tree

1 file changed

+9
-9
lines changed

1 file changed

+9
-9
lines changed

‎src/backend/commands/subscriptioncmds.c

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -556,18 +556,19 @@ AlterSubscription_refresh(Subscription *sub, bool copy_data)
556556
charstate;
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
charoriginname[NAMEDATALEN];
10641064
char*err=NULL;
1065-
WalReceiverConn*wrconn=NULL;
1065+
WalReceiverConn*wrconn;
10661066
Form_pg_subscriptionform;
10671067
List*rstates;
10681068

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp