Score:0

configure inactivity timeout while handling keepalive probes

pe flag

I am developing a TCP echo server using python and the socket library.

I'd like to have a timeout configured for each incoming connection. So to drop and close them if there is inactivity for a SOCK_TIMEOUT value.

This is achieve with the specific setting: client_sock.settimeout(SOCK_TIMEOUT)

At the same time I would like to maintain active the connection that use keepalive method. So, if a keepalive probe packet is received by the server from a given client I'd like to avoid the use of timeout to close this particular client/connection.

Problem clarification >> I'd like to have the server dropping every connection after 3 minutes of inactivity. This is achieved with the settimeout(SOCK_TIMEOUT) function. The main problem is that the current configuration and implementation of the TCP socket is not considering the keep-alive probe as "activity" thus, the connection is closed even if the probes are acknowledged.

Q1 >> Does this make sense?

I'd say this should be feasible. However, the socket server is unable to handle, as I desired, the keepalive probe. Because, even if those are acknowledged by the server, ACK is returned to each probe, the connection is closed at timeout.

Q2 >> Should I change the timeout implementation?

A.B avatar
cl flag
A.B
Afaik, tcp keepalive is transparent to the application. Ie: the application can't know this happens (even if it can configure settings for it to happen). If it can't know about it, this is moot. Why would you need to care about this? This looks like an [XY problem](https://xyproblem.info/): you need to solve a problem, but you never told us about it.
rebatoma avatar
pe flag
let me clarify the problem. I'd like to have the server dropping every connection after 3 minutes of inactivity. This is achieved with the `settimeout(SOCK_TIMEOUT)` function. The main problem is that the current configuration and implementation of the TCP socket is not considering the keep-alive probe as "activity" thus, the connection is closed even if the probes are acknowledged.
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.