mirror of
https://github.com/postgres/postgres.git
synced 2025-07-28 23:42:10 +03:00
Suppress duplicate error messages in pq_flush. Write error messages to
postmaster log with elog(DEBUG) so that they will be timestamped etc. Once upon a time I think elog() was unsafe here, but it shouldn't be anymore.
This commit is contained in:
@ -29,7 +29,7 @@
|
|||||||
* Portions Copyright (c) 1996-2001, PostgreSQL Global Development Group
|
* Portions Copyright (c) 1996-2001, PostgreSQL Global Development Group
|
||||||
* Portions Copyright (c) 1994, Regents of the University of California
|
* Portions Copyright (c) 1994, Regents of the University of California
|
||||||
*
|
*
|
||||||
* $Id: pqcomm.c,v 1.123 2001/11/05 17:46:25 momjian Exp $
|
* $Id: pqcomm.c,v 1.124 2001/11/12 04:54:08 tgl Exp $
|
||||||
*
|
*
|
||||||
*-------------------------------------------------------------------------
|
*-------------------------------------------------------------------------
|
||||||
*/
|
*/
|
||||||
@ -503,19 +503,18 @@ pq_recvbuf(void)
|
|||||||
continue; /* Ok if interrupted */
|
continue; /* Ok if interrupted */
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* We would like to use elog() here, but dare not because elog
|
* Careful: an elog() that tries to write to the client
|
||||||
* tries to write to the client, which will cause problems if
|
* would cause recursion to here, leading to stack overflow
|
||||||
* we have a hard communications failure ... So just write the
|
* and core dump! This message must go *only* to the postmaster
|
||||||
* message to the postmaster log.
|
* log. elog(DEBUG) is presently safe.
|
||||||
*/
|
*/
|
||||||
fprintf(stderr, "pq_recvbuf: recv() failed: %s\n",
|
elog(DEBUG, "pq_recvbuf: recv() failed: %m");
|
||||||
strerror(errno));
|
|
||||||
return EOF;
|
return EOF;
|
||||||
}
|
}
|
||||||
if (r == 0)
|
if (r == 0)
|
||||||
{
|
{
|
||||||
/* as above, elog not safe */
|
/* as above, only write to postmaster log */
|
||||||
fprintf(stderr, "pq_recvbuf: unexpected EOF on client connection\n");
|
elog(DEBUG, "pq_recvbuf: unexpected EOF on client connection");
|
||||||
return EOF;
|
return EOF;
|
||||||
}
|
}
|
||||||
/* r contains number of bytes read, so just incr length */
|
/* r contains number of bytes read, so just incr length */
|
||||||
@ -655,6 +654,8 @@ pq_putbytes(const char *s, size_t len)
|
|||||||
int
|
int
|
||||||
pq_flush(void)
|
pq_flush(void)
|
||||||
{
|
{
|
||||||
|
static int last_reported_send_errno = 0;
|
||||||
|
|
||||||
unsigned char *bufptr = PqSendBuffer;
|
unsigned char *bufptr = PqSendBuffer;
|
||||||
unsigned char *bufend = PqSendBuffer + PqSendPointer;
|
unsigned char *bufend = PqSendBuffer + PqSendPointer;
|
||||||
|
|
||||||
@ -675,12 +676,20 @@ pq_flush(void)
|
|||||||
continue; /* Ok if we were interrupted */
|
continue; /* Ok if we were interrupted */
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* We would like to use elog() here, but cannot because elog
|
* Careful: an elog() that tries to write to the client
|
||||||
* tries to write to the client, which would cause a recursive
|
* would cause recursion to here, leading to stack overflow
|
||||||
* flush attempt! So just write it out to the postmaster log.
|
* and core dump! This message must go *only* to the postmaster
|
||||||
|
* log. elog(DEBUG) is presently safe.
|
||||||
|
*
|
||||||
|
* If a client disconnects while we're in the midst of output,
|
||||||
|
* we might write quite a bit of data before we get to a safe
|
||||||
|
* query abort point. So, suppress duplicate log messages.
|
||||||
*/
|
*/
|
||||||
fprintf(stderr, "pq_flush: send() failed: %s\n",
|
if (errno != last_reported_send_errno)
|
||||||
strerror(errno));
|
{
|
||||||
|
last_reported_send_errno = errno;
|
||||||
|
elog(DEBUG, "pq_flush: send() failed: %m");
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* We drop the buffered data anyway so that processing can
|
* We drop the buffered data anyway so that processing can
|
||||||
@ -689,8 +698,11 @@ pq_flush(void)
|
|||||||
PqSendPointer = 0;
|
PqSendPointer = 0;
|
||||||
return EOF;
|
return EOF;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
last_reported_send_errno = 0; /* reset after any successful send */
|
||||||
bufptr += r;
|
bufptr += r;
|
||||||
}
|
}
|
||||||
|
|
||||||
PqSendPointer = 0;
|
PqSendPointer = 0;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@ -709,8 +721,8 @@ pq_eof(void)
|
|||||||
|
|
||||||
if (res < 0)
|
if (res < 0)
|
||||||
{
|
{
|
||||||
/* don't try to elog here... */
|
/* can log to postmaster log only */
|
||||||
fprintf(stderr, "pq_eof: recv() failed: %s\n", strerror(errno));
|
elog(DEBUG, "pq_eof: recv() failed: %m");
|
||||||
return EOF;
|
return EOF;
|
||||||
}
|
}
|
||||||
if (res == 0)
|
if (res == 0)
|
||||||
|
Reference in New Issue
Block a user