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

Commitc350b01

Browse files
committed
Fix canAcceptConnections() bugs introduced by replication-related patches.
We must not return any "okay to proceed" result code without having checkedfor too many children, else we might fail later on when trying to add thenew child to one of the per-child state arrays. It's not clear whetherthis oversight explains Stefan Kaltenbrunner's recent report, but it couldcertainly produce a similar symptom.Back-patch to 8.4; the logic was not broken before that.
1 parent9f65a87 commitc350b01

File tree

1 file changed

+19
-14
lines changed

1 file changed

+19
-14
lines changed

‎src/backend/postmaster/postmaster.c

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -349,7 +349,7 @@ static intProcessStartupPacket(Port *port, bool SSLdone);
349349
staticvoidprocessCancelRequest(Port*port,void*pkt);
350350
staticintinitMasks(fd_set*rmask);
351351
staticvoidreport_fork_failure_to_client(Port*port,interrnum);
352-
staticenumCAC_statecanAcceptConnections(void);
352+
staticCAC_statecanAcceptConnections(void);
353353
staticlongPostmasterRandom(void);
354354
staticvoidRandomSalt(char*md5Salt);
355355
staticvoidsignal_child(pid_tpid,intsignal);
@@ -1907,31 +1907,36 @@ processCancelRequest(Port *port, void *pkt)
19071907
/*
19081908
* canAcceptConnections --- check to see if database state allows connections.
19091909
*/
1910-
staticenumCAC_state
1910+
staticCAC_state
19111911
canAcceptConnections(void)
19121912
{
1913+
CAC_stateresult=CAC_OK;
1914+
19131915
/*
19141916
* Can't start backends when in startup/shutdown/inconsistent recovery
19151917
* state.
19161918
*
19171919
* In state PM_WAIT_BACKUP only superusers can connect (this must be
19181920
* allowed so that a superuser can end online backup mode); we return
19191921
* CAC_WAITBACKUP code to indicate that this must be checked later.
1922+
* Note that neither CAC_OK nor CAC_WAITBACKUP can safely be returned
1923+
* until we have checked for too many children.
19201924
*/
19211925
if (pmState!=PM_RUN)
19221926
{
19231927
if (pmState==PM_WAIT_BACKUP)
1924-
returnCAC_WAITBACKUP;/* allow superusers only */
1925-
if (Shutdown>NoShutdown)
1928+
result=CAC_WAITBACKUP;/* allow superusers only */
1929+
elseif (Shutdown>NoShutdown)
19261930
returnCAC_SHUTDOWN;/* shutdown is pending */
1927-
if (!FatalError&&
1928-
(pmState==PM_STARTUP||
1929-
pmState==PM_RECOVERY))
1930-
returnCAC_STARTUP;/* normal startup */
1931-
if (!FatalError&&
1932-
pmState==PM_HOT_STANDBY)
1933-
returnCAC_OK;/* connection OK during hot standby */
1934-
returnCAC_RECOVERY;/* else must be crash recovery */
1931+
elseif (!FatalError&&
1932+
(pmState==PM_STARTUP||
1933+
pmState==PM_RECOVERY))
1934+
returnCAC_STARTUP;/* normal startup */
1935+
elseif (!FatalError&&
1936+
pmState==PM_HOT_STANDBY)
1937+
result=CAC_OK;/* connection OK during hot standby */
1938+
else
1939+
returnCAC_RECOVERY;/* else must be crash recovery */
19351940
}
19361941

19371942
/*
@@ -1947,9 +1952,9 @@ canAcceptConnections(void)
19471952
* see comments for MaxLivePostmasterChildren().
19481953
*/
19491954
if (CountChildren(BACKEND_TYPE_ALL) >=MaxLivePostmasterChildren())
1950-
returnCAC_TOOMANY;
1955+
result=CAC_TOOMANY;
19511956

1952-
returnCAC_OK;
1957+
returnresult;
19531958
}
19541959

19551960

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp