Skip to content

Commit 30f5e1c

Browse files
lib:changes for making snmp socket non-blocking
Description: The changes have been done to make the snmp socket non-blocking before calling snmp_read() Problem Description/Summary : vtysh hangs on first try to enter after a reboot with BGP dynamic peers Expected Behavior : VTYSH should not hang When we debug more into bgpd docker by doing gdb on its threads, we find the below thread of bgpd, which is causing the issue. Thread 1 (Thread 0x7f1e1ec46d40 (LWP 47)): (gdb) bt The fix has been taken from the following link. https://sourceforge.net/p/net-snmp/patches/1348/ Signed-off-by: Preetham Singh ([email protected])
1 parent f7288f1 commit 30f5e1c

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

lib/agentx.c

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,13 +55,32 @@ static int agentx_timeout(struct thread *t)
5555
static int agentx_read(struct thread *t)
5656
{
5757
fd_set fds;
58+
int flags;
59+
int nonblock = false;
5860
struct listnode *ln = THREAD_ARG(t);
5961
list_delete_node(events, ln);
6062

63+
/* fix for non blocking socket */
64+
flags = fcntl(THREAD_FD(t), F_GETFL, 0);
65+
if (-1 == flags) {
66+
return -1;
67+
}
68+
69+
if (flags & O_NONBLOCK) {
70+
nonblock = true;
71+
} else {
72+
fcntl(THREAD_FD(t), F_SETFL, flags | O_NONBLOCK);
73+
}
74+
6175
FD_ZERO(&fds);
6276
FD_SET(THREAD_FD(t), &fds);
6377
snmp_read(&fds);
6478

79+
/* Reset the flag */
80+
if (!nonblock){
81+
fcntl(THREAD_FD(t), F_SETFL, flags);
82+
}
83+
6584
netsnmp_check_outstanding_agent_requests();
6685
agentx_events_update();
6786
return 0;

0 commit comments

Comments
 (0)