Skip to content

Commit c35ea8c

Browse files
tirupatihemanthvivekrnv
authored andcommitted
Update hsFlowd to close the pipe immediately (sonic-net#50)
Without this fix, sflowmgrd is taking 10-20 mins to finish command service restart hsflowd in Debian 13 sflowmgrd trace 0 read () from /lib/x86_64-linux-gnu/libc.so.6 1 _IO_file_underflow () from /lib/x86_64-linux-gnu/libc.so.6 2 _IO_default_uflow () from /lib/x86_64-linux-gnu/libc.so.6 3 _IO_getline_info () from /lib/x86_64-linux-gnu/libc.so.6 4 fgets () from /lib/x86_64-linux-gnu/libc.so.6 5 swss::exec(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >&) () from /lib/x86_64-linux-gnu/libswsscommon.so.0 6 swss::SflowMgr::sflowHandleService (this=this@entry=0x7ffdc4ae6dc0, enable=enable@entry=true) at ./cfgmgr/sflowmgr.cpp:67 7 swss::SflowMgr::doTask (this=<optimized out>, consumer=...) at ./cfgmgr/sflowmgr.cpp:459 8 Consumer::execute (this=0x556f0715b280) at ../orchagent/orch.cpp:338 9 main (argc=<optimized out>, argv=<optimized out>) at ./cfgmgr/sflowmgrd.cpp:74 hsflowd trace: (gdb) bt close () from /lib/x86_64-linux-gnu/libc.so.6 main (argc=<optimized out>, argv=<optimized out>) at hsflowd.c:1927 (gdb) f 1 1927 hsflowd.c: No such file or directory. (gdb) p i $1 = 1035943704 (gdb) c Continuing. ^C Program received signal SIGINT, Interrupt. 0x00007fa33f48d9e0 in close () from /lib/x86_64-linux-gnu/libc.so.6 (gdb) f 1 1927 in hsflowd.c (gdb) p i $2 = 1024299507 PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND 48 root 20 0 2652 928 820 R 92.4 0.0 5:24.66 hsflowd Signed-off-by: Vivek Reddy <vkarri@nvidia.com> Co-authored-by: Vivek Reddy <vkarri@nvidia.com>
1 parent 85ed5a6 commit c35ea8c

2 files changed

Lines changed: 46 additions & 0 deletions

File tree

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
From 5adeafc4249af9bc6a8841cff8ebbc75fcf4b8e1 Mon Sep 17 00:00:00 2001
2+
From: vkarri <vkarri@contoso.com>
3+
Date: Tue, 21 Oct 2025 01:23:08 +0000
4+
Subject: [PATCH] From dfc83d5cf6cbfa9056c4892d5ad0c3d3ac667d4f Mon Sep 17
5+
00:00:00 2001 Subject: [PATCH] Use close range syscall over blindly looping
6+
over all FD
7+
8+
getdtablesize is deprecated in Kernel 6.12 and Docker is returning a really large default number.
9+
So, hsflowd takes a lot of time to close all file descriptors and is blocking the service restart of hsflowd
10+
from sflowmgrd.
11+
---
12+
src/Linux/hsflowd.c | 9 +++++++--
13+
1 file changed, 7 insertions(+), 2 deletions(-)
14+
15+
diff --git a/src/Linux/hsflowd.c b/src/Linux/hsflowd.c
16+
index f7bd9a0..6170dc6 100644
17+
--- a/src/Linux/hsflowd.c
18+
+++ b/src/Linux/hsflowd.c
19+
@@ -6,6 +6,8 @@
20+
extern "C" {
21+
#endif
22+
23+
+#define _GNU_SOURCE
24+
+#include <unistd.h>
25+
#include "hsflowd.h"
26+
#include "cpu_utils.h"
27+
#include "cJSON.h"
28+
@@ -1922,9 +1924,12 @@ extern "C" {
29+
exit(EXIT_FAILURE);
30+
}
31+
32+
- // close all file descriptors
33+
+ // close all file descriptors using close_range() (Kernel 5.9+)
34+
int i;
35+
- for(i=getdtablesize(); i >= 0; --i) close(i);
36+
+ if(close_range(0, ~0U, 0) < 0) {
37+
+ myLog(LOG_ERR,"close_range failed: %s", strerror(errno));
38+
+ exit(EXIT_FAILURE);
39+
+ }
40+
// create stdin/out/err
41+
// stdin
42+
if((i = open("/dev/null",O_RDWR)) == -1) {
43+
--
44+
2.50.1
45+

src/sflow/hsflowd/patch/series

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@
22
0002-host_sflow_debian.patch
33
0003-sflow-enabled-drop-monitor-support-for-SONiC.patch
44
0004-When-interface-removed-just-as-we-discover-it-log-wi.patch
5+
0005-Use-close-range-syscall-over-blindly-looping-over-al.patch

0 commit comments

Comments
 (0)