Unverified Commit a2e75a78 authored by Viktor Söderqvist's avatar Viktor Söderqvist Committed by GitHub
Browse files

Include peer-addr:port and local-addr:port when logging accept errors (#11622)

The logged errors include these on the same format as in CLIENT INFO, e.g. "addr=127.0.0.1:12345 laddr=127.0.0.1:6379".
parent 4ef4c4a6
...@@ -40,6 +40,7 @@ ...@@ -40,6 +40,7 @@
static void setProtocolError(const char *errstr, client *c); static void setProtocolError(const char *errstr, client *c);
static void pauseClientsByClient(mstime_t end, int isPauseClientAll); static void pauseClientsByClient(mstime_t end, int isPauseClientAll);
int postponeClientRead(client *c); int postponeClientRead(client *c);
char *getClientSockname(client *c);
int ProcessingEventsWhileBlocked = 0; /* See processEventsWhileBlocked(). */ int ProcessingEventsWhileBlocked = 0; /* See processEventsWhileBlocked(). */
/* Return the size consumed from the allocator, for the specified SDS string, /* Return the size consumed from the allocator, for the specified SDS string,
...@@ -1228,8 +1229,8 @@ void clientAcceptHandler(connection *conn) { ...@@ -1228,8 +1229,8 @@ void clientAcceptHandler(connection *conn) {
if (connGetState(conn) != CONN_STATE_CONNECTED) { if (connGetState(conn) != CONN_STATE_CONNECTED) {
serverLog(LL_WARNING, serverLog(LL_WARNING,
"Error accepting a client connection: %s", "Error accepting a client connection: %s (addr=%s laddr=%s)",
connGetLastError(conn)); connGetLastError(conn), getClientPeerId(c), getClientSockname(c));
freeClientAsync(c); freeClientAsync(c);
return; return;
} }
...@@ -1279,14 +1280,16 @@ void clientAcceptHandler(connection *conn) { ...@@ -1279,14 +1280,16 @@ void clientAcceptHandler(connection *conn) {
void acceptCommonHandler(connection *conn, int flags, char *ip) { void acceptCommonHandler(connection *conn, int flags, char *ip) {
client *c; client *c;
char conninfo[100];
UNUSED(ip); UNUSED(ip);
if (connGetState(conn) != CONN_STATE_ACCEPTING) { if (connGetState(conn) != CONN_STATE_ACCEPTING) {
char addr[NET_ADDR_STR_LEN] = {0};
char laddr[NET_ADDR_STR_LEN] = {0};
connFormatAddr(conn, addr, sizeof(addr), 1);
connFormatAddr(conn, laddr, sizeof(addr), 0);
serverLog(LL_VERBOSE, serverLog(LL_VERBOSE,
"Accepted client connection in error state: %s (conn: %s)", "Accepted client connection in error state: %s (addr=%s laddr=%s)",
connGetLastError(conn), connGetLastError(conn), addr, laddr);
connGetInfo(conn, conninfo, sizeof(conninfo)));
connClose(conn); connClose(conn);
return; return;
} }
...@@ -1319,10 +1322,13 @@ void acceptCommonHandler(connection *conn, int flags, char *ip) { ...@@ -1319,10 +1322,13 @@ void acceptCommonHandler(connection *conn, int flags, char *ip) {
/* Create connection and client */ /* Create connection and client */
if ((c = createClient(conn)) == NULL) { if ((c = createClient(conn)) == NULL) {
char addr[NET_ADDR_STR_LEN] = {0};
char laddr[NET_ADDR_STR_LEN] = {0};
connFormatAddr(conn, addr, sizeof(addr), 1);
connFormatAddr(conn, laddr, sizeof(addr), 0);
serverLog(LL_WARNING, serverLog(LL_WARNING,
"Error registering fd event for the new client: %s (conn: %s)", "Error registering fd event for the new client connection: %s (addr=%s laddr=%s)",
connGetLastError(conn), connGetLastError(conn), addr, laddr);
connGetInfo(conn, conninfo, sizeof(conninfo)));
connClose(conn); /* May be already closed, just ignore errors */ connClose(conn); /* May be already closed, just ignore errors */
return; return;
} }
...@@ -1339,11 +1345,10 @@ void acceptCommonHandler(connection *conn, int flags, char *ip) { ...@@ -1339,11 +1345,10 @@ void acceptCommonHandler(connection *conn, int flags, char *ip) {
* Because of that, we must do nothing else afterwards. * Because of that, we must do nothing else afterwards.
*/ */
if (connAccept(conn, clientAcceptHandler) == C_ERR) { if (connAccept(conn, clientAcceptHandler) == C_ERR) {
char conninfo[100];
if (connGetState(conn) == CONN_STATE_ERROR) if (connGetState(conn) == CONN_STATE_ERROR)
serverLog(LL_WARNING, serverLog(LL_WARNING,
"Error accepting a client connection: %s (conn: %s)", "Error accepting a client connection: %s (addr=%s laddr=%s)",
connGetLastError(conn), connGetInfo(conn, conninfo, sizeof(conninfo))); connGetLastError(conn), getClientPeerId(c), getClientSockname(c));
freeClient(connGetPrivateData(conn)); freeClient(connGetPrivateData(conn));
return; return;
} }
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment