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

Commit2ad5c27

Browse files
committed
Don't send protocol messages to a shm_mq that no longer exists.
Commit2bd9e41 introduced a mechanismfor relaying protocol messages from a background worker to anotherbackend via a shm_mq. However, there was no provision for shuttingdown the communication channel. Therefore, a protocol message sentlate in the shutdown sequence, such as a DEBUG message resulting fromcranking up log_min_messages, could crash the server. To fix, installan on_dsm_detach callback that disables sending messages to the shm_mqwhen the associated DSM is detached.
1 parent3587cbc commit2ad5c27

File tree

3 files changed

+28
-4
lines changed

3 files changed

+28
-4
lines changed

‎src/backend/access/transam/parallel.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -867,7 +867,7 @@ ParallelWorkerMain(Datum main_arg)
867867
ParallelWorkerNumber*PARALLEL_ERROR_QUEUE_SIZE);
868868
shm_mq_set_sender(mq,MyProc);
869869
mqh=shm_mq_attach(mq,seg,NULL);
870-
pq_redirect_to_shm_mq(mq,mqh);
870+
pq_redirect_to_shm_mq(seg,mqh);
871871
pq_set_parallel_master(fps->parallel_master_pid,
872872
fps->parallel_master_backend_id);
873873

‎src/backend/libpq/pqmq.c

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ static bool pq_mq_busy = false;
2626
staticpid_tpq_mq_parallel_master_pid=0;
2727
staticpid_tpq_mq_parallel_master_backend_id=InvalidBackendId;
2828

29+
staticvoidpq_cleanup_redirect_to_shm_mq(dsm_segment*seg,Datumarg);
2930
staticvoidmq_comm_reset(void);
3031
staticintmq_flush(void);
3132
staticintmq_flush_if_writable(void);
@@ -51,13 +52,26 @@ static PQcommMethods PqCommMqMethods = {
5152
* message queue.
5253
*/
5354
void
54-
pq_redirect_to_shm_mq(shm_mq*mq,shm_mq_handle*mqh)
55+
pq_redirect_to_shm_mq(dsm_segment*seg,shm_mq_handle*mqh)
5556
{
5657
PqCommMethods=&PqCommMqMethods;
57-
pq_mq=mq;
58+
pq_mq=shm_mq_get_queue(mqh);
5859
pq_mq_handle=mqh;
5960
whereToSendOutput=DestRemote;
6061
FrontendProtocol=PG_PROTOCOL_LATEST;
62+
on_dsm_detach(seg,pq_cleanup_redirect_to_shm_mq, (Datum)0);
63+
}
64+
65+
/*
66+
* When the DSM that contains our shm_mq goes away, we need to stop sending
67+
* messages to it.
68+
*/
69+
staticvoid
70+
pq_cleanup_redirect_to_shm_mq(dsm_segment*seg,Datumarg)
71+
{
72+
pq_mq=NULL;
73+
pq_mq_handle=NULL;
74+
whereToSendOutput=DestNone;
6175
}
6276

6377
/*
@@ -123,9 +137,19 @@ mq_putmessage(char msgtype, const char *s, size_t len)
123137
if (pq_mq!=NULL)
124138
shm_mq_detach(pq_mq);
125139
pq_mq=NULL;
140+
pq_mq_handle=NULL;
126141
returnEOF;
127142
}
128143

144+
/*
145+
* If the message queue is already gone, just ignore the message. This
146+
* doesn't necessarily indicate a problem; for example, DEBUG messages
147+
* can be generated late in the shutdown sequence, after all DSMs have
148+
* already been detached.
149+
*/
150+
if (pq_mq==NULL)
151+
return0;
152+
129153
pq_mq_busy= true;
130154

131155
iov[0].data=&msgtype;

‎src/include/libpq/pqmq.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
#include"lib/stringinfo.h"
1717
#include"storage/shm_mq.h"
1818

19-
externvoidpq_redirect_to_shm_mq(shm_mq*,shm_mq_handle*);
19+
externvoidpq_redirect_to_shm_mq(dsm_segment*seg,shm_mq_handle*mqh);
2020
externvoidpq_set_parallel_master(pid_tpid,BackendIdbackend_id);
2121

2222
externvoidpq_parse_errornotice(StringInfostr,ErrorData*edata);

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp