Skip to content

Commit 7348476

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 7348476

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

lib/agentx.c

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,13 +55,33 @@ 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+
}
72+
else{
73+
fcntl(THREAD_FD(t), F_SETFL, flags | O_NONBLOCK);
74+
}
75+
6176
FD_ZERO(&fds);
6277
FD_SET(THREAD_FD(t), &fds);
6378
snmp_read(&fds);
6479

80+
/* Reset the flag */
81+
if (!nonblock){
82+
fcntl(THREAD_FD(t), F_SETFL, flags);
83+
}
84+
6585
netsnmp_check_outstanding_agent_requests();
6686
agentx_events_update();
6787
return 0;

0 commit comments

Comments
 (0)