Skip to content

Commit 5632d6e

Browse files
committed
Don't send "cannot connect" errors on invalid startup packet
Commit 16671ba moved the code that sends "sorry, too many clients already" and other such messages, but it had the effect that we would send that error even if the the startup packet processing failed, e.g. because the client sent an invalid startup packet. That was not intentional. Spotted while reading the code again.
1 parent 4710b67 commit 5632d6e

File tree

1 file changed

+34
-31
lines changed

1 file changed

+34
-31
lines changed

src/backend/postmaster/postmaster.c

Lines changed: 34 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -4354,42 +4354,45 @@ BackendInitialize(Port *port)
43544354
* now instead of wasting cycles on an authentication exchange. (This also
43554355
* allows a pg_ping utility to be written.)
43564356
*/
4357-
switch (port->canAcceptConnections)
4357+
if (status == STATUS_OK)
43584358
{
4359-
case CAC_STARTUP:
4360-
ereport(FATAL,
4361-
(errcode(ERRCODE_CANNOT_CONNECT_NOW),
4362-
errmsg("the database system is starting up")));
4363-
break;
4364-
case CAC_NOTCONSISTENT:
4365-
if (EnableHotStandby)
4359+
switch (port->canAcceptConnections)
4360+
{
4361+
case CAC_STARTUP:
43664362
ereport(FATAL,
43674363
(errcode(ERRCODE_CANNOT_CONNECT_NOW),
4368-
errmsg("the database system is not yet accepting connections"),
4369-
errdetail("Consistent recovery state has not been yet reached.")));
4370-
else
4364+
errmsg("the database system is starting up")));
4365+
break;
4366+
case CAC_NOTCONSISTENT:
4367+
if (EnableHotStandby)
4368+
ereport(FATAL,
4369+
(errcode(ERRCODE_CANNOT_CONNECT_NOW),
4370+
errmsg("the database system is not yet accepting connections"),
4371+
errdetail("Consistent recovery state has not been yet reached.")));
4372+
else
4373+
ereport(FATAL,
4374+
(errcode(ERRCODE_CANNOT_CONNECT_NOW),
4375+
errmsg("the database system is not accepting connections"),
4376+
errdetail("Hot standby mode is disabled.")));
4377+
break;
4378+
case CAC_SHUTDOWN:
43714379
ereport(FATAL,
43724380
(errcode(ERRCODE_CANNOT_CONNECT_NOW),
4373-
errmsg("the database system is not accepting connections"),
4374-
errdetail("Hot standby mode is disabled.")));
4375-
break;
4376-
case CAC_SHUTDOWN:
4377-
ereport(FATAL,
4378-
(errcode(ERRCODE_CANNOT_CONNECT_NOW),
4379-
errmsg("the database system is shutting down")));
4380-
break;
4381-
case CAC_RECOVERY:
4382-
ereport(FATAL,
4383-
(errcode(ERRCODE_CANNOT_CONNECT_NOW),
4384-
errmsg("the database system is in recovery mode")));
4385-
break;
4386-
case CAC_TOOMANY:
4387-
ereport(FATAL,
4388-
(errcode(ERRCODE_TOO_MANY_CONNECTIONS),
4389-
errmsg("sorry, too many clients already")));
4390-
break;
4391-
case CAC_OK:
4392-
break;
4381+
errmsg("the database system is shutting down")));
4382+
break;
4383+
case CAC_RECOVERY:
4384+
ereport(FATAL,
4385+
(errcode(ERRCODE_CANNOT_CONNECT_NOW),
4386+
errmsg("the database system is in recovery mode")));
4387+
break;
4388+
case CAC_TOOMANY:
4389+
ereport(FATAL,
4390+
(errcode(ERRCODE_TOO_MANY_CONNECTIONS),
4391+
errmsg("sorry, too many clients already")));
4392+
break;
4393+
case CAC_OK:
4394+
break;
4395+
}
43934396
}
43944397

43954398
/*

0 commit comments

Comments
 (0)