diff options
author | Andrew Dunstan <andrew@dunslane.net> | 2019-03-06 15:27:19 -0500 |
---|---|---|
committer | Andrew Dunstan <andrew@dunslane.net> | 2019-03-06 15:36:41 -0500 |
commit | 342cb650e0ffc7a007a12a419be04d47da4bd8cc (patch) | |
tree | e6c9e43f1907d72c5e0f74fdd3316fcc5099e4c1 | |
parent | b1723423216749be9b28f8430c3b7180dec3fa70 (diff) | |
download | postgresql-342cb650e0ffc7a007a12a419be04d47da4bd8cc.tar.gz postgresql-342cb650e0ffc7a007a12a419be04d47da4bd8cc.zip |
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
-rw-r--r-- | src/backend/postmaster/postmaster.c | 33 |
1 files changed, 25 insertions, 8 deletions
diff --git a/src/backend/postmaster/postmaster.c b/src/backend/postmaster/postmaster.c index ccea231e985..fe599632d3d 100644 --- a/src/backend/postmaster/postmaster.c +++ b/src/backend/postmaster/postmaster.c @@ -1899,17 +1899,34 @@ ProcessStartupPacket(Port *port, bool SSLdone) MemoryContext oldcontext; pq_startmsgread(); - if (pq_getbytes((char *) &len, 4) == EOF) + + /* + * Grab the first byte of the length word separately, so that we can tell + * whether we have no data at all or an incomplete packet. (This might + * sound inefficient, but it's not really, because of buffering in + * pqcomm.c.) + */ + if (pq_getbytes((char *) &len, 1) == EOF) { /* - * EOF after SSLdone probably means the client didn't like our - * response to NEGOTIATE_SSL_CODE. That's not an error condition, so - * don't clutter the log with a complaint. + * If we get no data at all, don't clutter the log with a complaint; + * such cases often occur for legitimate reasons. An example is that + * we might be here after responding to NEGOTIATE_SSL_CODE, and if the + * client didn't like our response, it'll probably just drop the + * connection. Service-monitoring software also often just opens and + * closes a connection without sending anything. (So do port + * scanners, which may be less benign, but it's not really our job to + * notice those.) */ - if (!SSLdone) - ereport(COMMERROR, - (errcode(ERRCODE_PROTOCOL_VIOLATION), - errmsg("incomplete startup packet"))); + return STATUS_ERROR; + } + + if (pq_getbytes(((char *) &len) + 1, 3) == EOF) + { + /* Got a partial length word, so bleat about that */ + ereport(COMMERROR, + (errcode(ERRCODE_PROTOCOL_VIOLATION), + errmsg("incomplete startup packet"))); return STATUS_ERROR; } |