From 9ac56b28614f1bdbe147181471a6688f4f418e9f Mon Sep 17 00:00:00 2001 From: Rainer Gerhards Date: Sun, 15 Sep 2024 15:24:28 +0200 Subject: [PATCH] network subsystem: improve connection failure error message If we try to connect via TCP and the connections fails, we now tell inside the error message how long the connection attempt took. This is useful to find out if targets connect very slowly. --- runtime/nsd_ptcp.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/runtime/nsd_ptcp.c b/runtime/nsd_ptcp.c index e1c1de957..8549d5aaa 100644 --- a/runtime/nsd_ptcp.c +++ b/runtime/nsd_ptcp.c @@ -37,6 +37,7 @@ #include #include #include +#include #include "rsyslog.h" #include "syslogd-types.h" @@ -73,6 +74,7 @@ DEFobjCurrIf(prop) static void sockClose(int *pSock) { + fprintf(stderr, "nsd_ptcp: closing socket %d\n", *pSock); if(*pSock >= 0) { close(*pSock); *pSock = -1; @@ -956,9 +958,15 @@ Connect(nsd_t *pNsd, int family, uchar *port, uchar *host, char *device) } } + struct timeval start, end; + long seconds, useconds; + gettimeofday(&start, NULL); if(connect(pThis->sock, res->ai_addr, res->ai_addrlen) != 0) { - LogError(errno, RS_RET_IO_ERROR, "cannot connect to %s:%s", - host, port); + gettimeofday(&end, NULL); + seconds = end.tv_sec - start.tv_sec; + useconds = end.tv_usec - start.tv_usec; + LogError(errno, RS_RET_IO_ERROR, "cannot connect to %s:%s (took %ld.%ld seconds)", + host, port, seconds, useconds / 10000); ABORT_FINALIZE(RS_RET_IO_ERROR); } -- 2.33.0