Select () hangs endlessly

I have an application that runs on embedded Linux (earlier kernel, 2.6.18). I am using Live555. Sometimes, when the camera is heavily loaded, my RTSP server (built using Live555) will hang indefinitely - no number of connections or cajoling seems to allow it to disconnect from it without waiting for the application to reset.

I narrowed the hang to this code:

static int blockUntilReadable(UsageEnvironment& env, int socket, struct timeval* timeout) { int result = -1; do { fd_set rd_set; FD_ZERO(&rd_set); if (socket < 0) break; FD_SET((unsigned) socket, &rd_set); const unsigned numFds = socket+1; result = select(numFds, &rd_set, NULL, NULL, timeout); <--HANG 

timeout is, of course, a NULL pointer, which indicates that it should block until one of the sockets is readable. The problem is that it doesn't matter if I connect to the RTSP server - it just blocks endlessly.

I did netstat -an and it always outputs something like:

 Active Internet connections (servers and established) Proto Recv-Q Send-Q Local Address Foreign Address State tcp 0 0 0.0.0.0:5222 0.0.0.0:* LISTEN tcp 0 0 0.0.0.0:5800 0.0.0.0:* LISTEN tcp 0 0 0.0.0.0:5000 0.0.0.0:* LISTEN tcp 0 0 0.0.0.0:5802 0.0.0.0:* LISTEN tcp 21 0 0.0.0.0:554 0.0.0.0:* LISTEN 

When it is in a failed state, I always see 21 in Recv-Q, which represents "The number of bytes not copied by the user program connected to this socket."

Does anyone know what can go south, or how can I fix this problem?

+4
source share
1 answer

This code looks pretty solid. I'm a little curious why you chose unsigned int , but that shouldn't hurt anything.

Some thoughts:

It does not hang where you think. Hope you double / triple checked this. (Check again?)

Your interpretation of netstat is incorrect. This part, as the manual page notes, is intended for "installed" sockets - yours is a listener, which is the following sentence: "Listening: since kernel 2.6.18 this column contains the current synchronization lag."

This seems like a huge lag ... It makes me think that you are not accepting (), perhaps because you are stuck in select (). Is it correct to select select () in your socket for listening?

Finally, double check that you are calling select () on the right socket . those. print this arg socket, and see what it should be.

Essentially check: 1) it hangs in select () and 2) the arguments for the selection are correct. I suspect that one of these two is incorrect.

+2
source

Source: https://habr.com/ru/post/1311923/


All Articles