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

Commit3892a2d

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 parent1bd2012 commit3892a2d

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
@@ -350,7 +350,7 @@ static intProcessStartupPacket(Port *port, bool SSLdone);
350350
staticvoidprocessCancelRequest(Port*port,void*pkt);
351351
staticintinitMasks(fd_set*rmask);
352352
staticvoidreport_fork_failure_to_client(Port*port,interrnum);
353-
staticenumCAC_statecanAcceptConnections(void);
353+
staticCAC_statecanAcceptConnections(void);
354354
staticlongPostmasterRandom(void);
355355
staticvoidRandomSalt(char*md5Salt);
356356
staticvoidsignal_child(pid_tpid,intsignal);
@@ -1908,31 +1908,36 @@ processCancelRequest(Port *port, void *pkt)
19081908
/*
19091909
* canAcceptConnections --- check to see if database state allows connections.
19101910
*/
1911-
staticenumCAC_state
1911+
staticCAC_state
19121912
canAcceptConnections(void)
19131913
{
1914+
CAC_stateresult=CAC_OK;
1915+
19141916
/*
19151917
* Can't start backends when in startup/shutdown/inconsistent recovery
19161918
* state.
19171919
*
19181920
* In state PM_WAIT_BACKUP only superusers can connect (this must be
19191921
* allowed so that a superuser can end online backup mode); we return
19201922
* CAC_WAITBACKUP code to indicate that this must be checked later.
1923+
* Note that neither CAC_OK nor CAC_WAITBACKUP can safely be returned
1924+
* until we have checked for too many children.
19211925
*/
19221926
if (pmState!=PM_RUN)
19231927
{
19241928
if (pmState==PM_WAIT_BACKUP)
1925-
returnCAC_WAITBACKUP;/* allow superusers only */
1926-
if (Shutdown>NoShutdown)
1929+
result=CAC_WAITBACKUP;/* allow superusers only */
1930+
elseif (Shutdown>NoShutdown)
19271931
returnCAC_SHUTDOWN;/* shutdown is pending */
1928-
if (!FatalError&&
1929-
(pmState==PM_STARTUP||
1930-
pmState==PM_RECOVERY))
1931-
returnCAC_STARTUP;/* normal startup */
1932-
if (!FatalError&&
1933-
pmState==PM_HOT_STANDBY)
1934-
returnCAC_OK;/* connection OK during hot standby */
1935-
returnCAC_RECOVERY;/* else must be crash recovery */
1932+
elseif (!FatalError&&
1933+
(pmState==PM_STARTUP||
1934+
pmState==PM_RECOVERY))
1935+
returnCAC_STARTUP;/* normal startup */
1936+
elseif (!FatalError&&
1937+
pmState==PM_HOT_STANDBY)
1938+
result=CAC_OK;/* connection OK during hot standby */
1939+
else
1940+
returnCAC_RECOVERY;/* else must be crash recovery */
19361941
}
19371942

19381943
/*
@@ -1948,9 +1953,9 @@ canAcceptConnections(void)
19481953
* see comments for MaxLivePostmasterChildren().
19491954
*/
19501955
if (CountChildren(BACKEND_TYPE_ALL) >=MaxLivePostmasterChildren())
1951-
returnCAC_TOOMANY;
1956+
result=CAC_TOOMANY;
19521957

1953-
returnCAC_OK;
1958+
returnresult;
19541959
}
19551960

19561961

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp