Skip to content

Commit 342cb65

Browse files
committed
Don't log incomplete startup packet if it's empty
This will stop logging cases where, for example, a monitor opens a connection and immediately closes it. If the packet contains any data an incomplete packet will still be logged. Author: Tom Lane Discussion: https://postgr.es/m/a1379a72-2958-1ed0-ef51-09a21219b155@2ndQuadrant.com
1 parent b172342 commit 342cb65

File tree

1 file changed

+25
-8
lines changed

1 file changed

+25
-8
lines changed

src/backend/postmaster/postmaster.c

Lines changed: 25 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1899,17 +1899,34 @@ ProcessStartupPacket(Port *port, bool SSLdone)
18991899
MemoryContext oldcontext;
19001900

19011901
pq_startmsgread();
1902-
if (pq_getbytes((char *) &len, 4) == EOF)
1902+
1903+
/*
1904+
* Grab the first byte of the length word separately, so that we can tell
1905+
* whether we have no data at all or an incomplete packet. (This might
1906+
* sound inefficient, but it's not really, because of buffering in
1907+
* pqcomm.c.)
1908+
*/
1909+
if (pq_getbytes((char *) &len, 1) == EOF)
19031910
{
19041911
/*
1905-
* EOF after SSLdone probably means the client didn't like our
1906-
* response to NEGOTIATE_SSL_CODE. That's not an error condition, so
1907-
* don't clutter the log with a complaint.
1912+
* If we get no data at all, don't clutter the log with a complaint;
1913+
* such cases often occur for legitimate reasons. An example is that
1914+
* we might be here after responding to NEGOTIATE_SSL_CODE, and if the
1915+
* client didn't like our response, it'll probably just drop the
1916+
* connection. Service-monitoring software also often just opens and
1917+
* closes a connection without sending anything. (So do port
1918+
* scanners, which may be less benign, but it's not really our job to
1919+
* notice those.)
19081920
*/
1909-
if (!SSLdone)
1910-
ereport(COMMERROR,
1911-
(errcode(ERRCODE_PROTOCOL_VIOLATION),
1912-
errmsg("incomplete startup packet")));
1921+
return STATUS_ERROR;
1922+
}
1923+
1924+
if (pq_getbytes(((char *) &len) + 1, 3) == EOF)
1925+
{
1926+
/* Got a partial length word, so bleat about that */
1927+
ereport(COMMERROR,
1928+
(errcode(ERRCODE_PROTOCOL_VIOLATION),
1929+
errmsg("incomplete startup packet")));
19131930
return STATUS_ERROR;
19141931
}
19151932

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy