Skip to content

Commit a3eb715

Browse files
committed
Make walsender always initialize the buffers.
Walsender uses the local buffers for each outgoing and incoming message. Previously when creating replication slot, walsender forgot to initialize one of them and which can cause the segmentation fault error. To fix this issue, this commit changes walsender so that it always initialize them before it executes the requested replication command. Back-patch to 9.4 where replication slot was introduced. Problem report and initial patch by Stas Kelvich, modified by me. Report: https://www.postgresql.org/message-id/A1E9CB90-1FAC-4CAD-8DBA-9AA62A6E97C5@postgrespro.ru
1 parent d9959e6 commit a3eb715

File tree

1 file changed

+8
-10
lines changed

1 file changed

+8
-10
lines changed

src/backend/replication/walsender.c

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -805,8 +805,6 @@ CreateReplicationSlot(CreateReplicationSlotCmd *cmd)
805805
ReplicationSlotCreate(cmd->slotname, true, RS_EPHEMERAL);
806806
}
807807

808-
initStringInfo(&output_message);
809-
810808
if (cmd->kind == REPLICATION_KIND_LOGICAL)
811809
{
812810
LogicalDecodingContext *ctx;
@@ -1310,6 +1308,14 @@ exec_replication_command(const char *cmd_string)
13101308

13111309
cmd_node = replication_parse_result;
13121310

1311+
/*
1312+
* Allocate buffers that will be used for each outgoing and incoming
1313+
* message. We do this just once per command to reduce palloc overhead.
1314+
*/
1315+
initStringInfo(&output_message);
1316+
initStringInfo(&reply_message);
1317+
initStringInfo(&tmpbuf);
1318+
13131319
switch (cmd_node->type)
13141320
{
13151321
case T_IdentifySystemCmd:
@@ -1782,14 +1788,6 @@ WalSndCheckTimeOut(TimestampTz now)
17821788
static void
17831789
WalSndLoop(WalSndSendDataCallback send_data)
17841790
{
1785-
/*
1786-
* Allocate buffers that will be used for each outgoing and incoming
1787-
* message. We do this just once to reduce palloc overhead.
1788-
*/
1789-
initStringInfo(&output_message);
1790-
initStringInfo(&reply_message);
1791-
initStringInfo(&tmpbuf);
1792-
17931791
/*
17941792
* Initialize the last reply timestamp. That enables timeout processing
17951793
* from hereon.

0 commit comments

Comments
 (0)