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

Commit799b23c

Browse files
kovdb75MakSl
authored andcommitted
[PGPRO-5531] Fixed crashes in the receive_msg_by_parts function
1 parentf891d8a commit799b23c

File tree

2 files changed

+43
-10
lines changed

2 files changed

+43
-10
lines changed

‎pg_query_state.c‎

Lines changed: 38 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ static void qs_ExecutorRun(QueryDesc *queryDesc, ScanDirection direction,
6161
staticvoidqs_ExecutorFinish(QueryDesc*queryDesc);
6262

6363
staticshm_mq_resultreceive_msg_by_parts(shm_mq_handle*mqh,Size*total,
64-
void**datap,boolnowait);
64+
void**datap,int64timeout,int*rc,boolnowait);
6565

6666
/* Global variables */
6767
List*QueryDescStack=NIL;
@@ -780,7 +780,7 @@ shm_mq_receive_with_timeout(shm_mq_handle *mqh,
780780
{
781781
shm_mq_resultmq_receive_result;
782782

783-
mq_receive_result=receive_msg_by_parts(mqh,nbytesp,datap, true);
783+
mq_receive_result=receive_msg_by_parts(mqh,nbytesp,datap,timeout,&rc,true);
784784
if (mq_receive_result!=SHM_MQ_WOULD_BLOCK)
785785
returnmq_receive_result;
786786
if (rc&WL_TIMEOUT||delay <=0)
@@ -967,33 +967,61 @@ copy_msg(shm_mq_msg *msg)
967967

968968
staticshm_mq_result
969969
receive_msg_by_parts(shm_mq_handle*mqh,Size*total,void**datap,
970-
boolnowait)
970+
int64timeout,int*rc,boolnowait)
971971
{
972972
shm_mq_resultmq_receive_result;
973973
shm_mq_msg*buff;
974974
intoffset;
975-
Size*expected;
976-
Sizeexpected_data;
975+
Size*expected;
976+
Sizeexpected_data;
977977
Sizelen;
978978

979979
/* Get the expected number of bytes in message */
980980
mq_receive_result=shm_mq_receive(mqh,&len, (void**)&expected,nowait);
981-
expected_data=*expected;
982981
if (mq_receive_result!=SHM_MQ_SUCCESS)
983982
returnmq_receive_result;
984983
Assert(len==sizeof(Size));
985984

985+
expected_data=*expected;
986986
*datap=palloc0(expected_data);
987987

988988
/* Get the message itself */
989989
for (offset=0;offset<expected_data; )
990990
{
991+
int64delay=timeout;
991992
/* Keep receiving new messages until we assemble the full message */
992-
mq_receive_result=shm_mq_receive(mqh,&len, ((void**)&buff),nowait);
993+
for (;;)
994+
{
995+
mq_receive_result=shm_mq_receive(mqh,&len, ((void**)&buff),nowait);
996+
if (mq_receive_result!=SHM_MQ_SUCCESS)
997+
{
998+
if (nowait&&mq_receive_result==SHM_MQ_WOULD_BLOCK)
999+
{
1000+
/*
1001+
* We can't leave this function during reading parts with
1002+
* error code SHM_MQ_WOULD_BLOCK because can be be error
1003+
* at next call receive_msg_by_parts() with continuing
1004+
* reading non-readed parts.
1005+
* So we should wait whole MAX_RCV_TIMEOUT timeout and
1006+
* return error after that only.
1007+
*/
1008+
if (delay>0)
1009+
{
1010+
pg_usleep(PART_RCV_DELAY*1000);
1011+
delay-=PART_RCV_DELAY;
1012+
continue;
1013+
}
1014+
if (rc)
1015+
{/* Mark that the timeout has expired: */
1016+
*rc |=WL_TIMEOUT;
1017+
}
1018+
}
1019+
returnmq_receive_result;
1020+
}
1021+
break;
1022+
}
9931023
memcpy((char*)*datap+offset,buff,len);
9941024
offset+=len;
995-
if (mq_receive_result!=SHM_MQ_SUCCESS)
996-
returnmq_receive_result;
9971025
}
9981026

9991027
*total=offset;
@@ -1074,7 +1102,7 @@ GetRemoteBackendQueryStates(PGPROC *leader,
10741102
mqh=shm_mq_attach(mq,NULL,NULL);
10751103
elog(DEBUG1,"Wait response from leader %d",leader->pid);
10761104
mq_receive_result=receive_msg_by_parts(mqh,&len, (void**)&msg,
1077-
false);
1105+
0,NULL,false);
10781106
if (mq_receive_result!=SHM_MQ_SUCCESS)
10791107
gotomq_error;
10801108
if (msg->reqid!=reqid)

‎pg_query_state.h‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,11 @@
3131
#defineMAX_RCV_TIMEOUT 6000/* 6 seconds */
3232
#defineMAX_SND_TIMEOUT 3000/* 3 seconds */
3333

34+
/*
35+
* Delay for receiving parts of full message (in case SHM_MQ_WOULD_BLOCK code),
36+
* should be tess than MAX_RCV_TIMEOUT
37+
*/
38+
#definePART_RCV_DELAY 1000/* 1 second */
3439

3540
/*
3641
* Result status on query state request from asked backend

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp