index > Winsock Kernel (WSK) > Keepalive Timeout Detection

Keepalive Timeout Detection


Hi

I seem to be seeing some strange behavior in a half-open connection where keepalives stop receiving acknowledgements after a while.

I have a simple client and server talking to each other through WinSock apis. After establishing a connection from my client to the server, the server uses setsockopt to send keepalives to the client every 20 seconds. At this state, I see the keepalives being sent by the server and these packets are being acknowledged by the client. Subsequently, I issue a half-close through my client (send a FIN to close the send side of the connection, but leave the receive side open). Following this, I see that the server sends one set of keepalives that are acknowledged. But after some time, the keepalives on the server mysteriously stop receiving acknowledgements. The server sends about 5 such keepalives and then gives up. When I did a netstat, the connection was already gone on the server. However, my server application was not notified about this event. Is there a way by which I can be notified in my application of failed keepalives on the socket? I tried to do a getsockopt(sock, SOL_SOCKET, SO_ERROR...), but that did not return with any errors on this socket even after the keepalives started timing out. I tried a couple of other functions like getpeername, etc and even these returned success.

Any ideas on how I'd be able to detect keepalive timeouts on windows?

Thanks!
iknownoone
If your server application has issued a blocking read using API recv(...), which should be in blocking mode before this problem happens, then, as soon as max retries, 5, is reached, the tcp/ip driver will reset that connection. You'll see that the recv() operation returned with errno 10054. This reset will come from local TCP/IP stack not from remote peer. The following example shows a thread doing the recv() , but this could be done anywhere in your code, (e.g main function).
DWORD WINAPI MyReceiver(VOID threadArg)
{
INT nRet = 0;
while(1)
{
nRet = recv(......); // blocks if no data available
if(nRet <= 0)
{
// handle error
printf("recv() failed, errno %d\n",WSAGetLastError());
}
} // end of while
}
If keep alive max retries was reached, you "should" see something like this:
recv() failed, errno 10054
Hope it helps.
mauro007
mauro,

Thanks for your reply.

True that receives will return with an error, but if you observe, I dont have the option of calling a "recv" in my server code. The server has just received a FIN from the client to close one end of the connection (half-close) and so, I'll need some other way of detecting this error. Also, if you do a tcpdump, you will observe that the server does not send a "RST" for this connection (I tested this case).
iknownoone
reply 3

You can use google to search for other answers

 

More Articles

• Winsock2 API - receiving data
• Problem with UDP
• Communicating with/from VLAN machines - Issues
• KeepAlive (Keep Alive) not working on Win2003 Enterprise 64 bit E...
• Need to know the IP address and mask in kernel driver
• UDP client and server application program on the same machine in ...
• WSK and Game Development
• Enable double ip addresses
• Windows Core Networking Online Chat today at 11AM PST
• Windows kernel mode ARP
Welcome to Bokebb   New Update   Joins the collection  
 

New Articles

• Windows kernel mode ARP
• UDP client and server application progra
• Winsock2 API - receiving data
• Windows Core Networking Online Chat toda
• winsock app works on win 2k server but _
• KeepAlive (Keep Alive) not working on Wi
• New to Socket Programming
• Keepalive Timeout Detection
• Enable double ip addresses
• Trying to use Winsock control in Microso
• InternetOpen with specific IP address wh
• Problem with UDP
• HTTP Keep Alive and Local Port
• WSK and Game Development
• Need to know the IP address and mask in

Hot Articles

• Communicating with/from VLAN machines -
• UDP client and server application progra
• Trying to use Winsock control in Microso
• Keepalive Timeout Detection
• Why can't maximum length of the queue of
• HTTP Keep Alive and Local Port
• Need to know the IP address and mask in
• New to Socket Programming
• KeepAlive (Keep Alive) not working on Wi
• Windows Core Networking Online Chat toda
• winsock app works on win 2k server but _
• Identifying WiFi Access Points
• Windows kernel mode ARP
• Enable double ip addresses
• InternetOpen with specific IP address wh

Recommend Articles

• Trying to use Winsock control in Microso
• Windows kernel mode ARP
• KeepAlive (Keep Alive) not working on Wi
• HTTP Keep Alive and Local Port
• Why can't maximum length of the queue of
• Identifying WiFi Access Points
• Winsock2 API - receiving data
• New to Socket Programming
• WSK and Game Development
• UDP client and server application progra
• Windows Core Networking Online Chat toda
• Enable double ip addresses
• Communicating with/from VLAN machines -
• Need to know the IP address and mask in
• winsock app works on win 2k server but _