rsyslog/backport-network-subsystem-improve-connection-failure-error-m.patch
Qiumiao Zhang 75963a8e86 backport some patches from upstream
Signed-off-by: Qiumiao Zhang <zhangqiumiao1@huawei.com>
(cherry picked from commit b01474022f935c55473f71b9f92f7f36fd8fd708)
2024-12-21 17:40:45 +08:00

55 lines
1.6 KiB
Diff

From 9ac56b28614f1bdbe147181471a6688f4f418e9f Mon Sep 17 00:00:00 2001
From: Rainer Gerhards <rgerhards@adiscon.com>
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 <fcntl.h>
#include <unistd.h>
#include <netinet/tcp.h>
+#include <sys/time.h>
#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