Page 1 of 1

TCPEndpoint too many TIME_WAIT

Posted: Tue Mar 05, 2019 1:38 pm
by lodge
when use TCPEndpoint,client call server 1 call/sec,later the client cann't connect to the server, because the client system have too many TIIME_WAIT,how can i solve this question?

code1:
void post_status()
{
RcfClient<I_Interface> client(RCF::TcpEndpoint("127.0.0.1", 12345));
client.getClientStub().setConnectTimeoutMs(timeout);
client.getClientStub().setRemoteCallTimeoutMs(timeout);
client.post_status(RCF::Oneway, 1, 2, 3);
}

DWORD dwTick = GetTickCount();
while(true)
{
if (GetTickCount() - dwTick >= 1000)
{
post_status();
dwTick = GetTickCount();
}
Sleep(50);
}

in this example,system have many TIME_WAIT like this:
TIME_WAIT1:
local->127.0.0.1:10000<>remote->127.0.0.1:12345
local->127.0.0.1:10001<>remote->127.0.0.1:12345
local->127.0.0.1:10002<>remote->127.0.0.1:12345
local->127.0.0.1:10003<>remote->127.0.0.1:12345
......
local->127.0.0.1:65535<>remote->127.0.0.1:12345

TIME_WAIT2:
local->127.0.0.1:XXX<>remote->127.0.0.1:XXX
local->127.0.0.1:XXX<>remote->127.0.0.1:XXX
.....
local->127.0.0.1:XXX<>remote->127.0.0.1:XXX

now post_status cann't connect the server and throw exception the exception code is 16.

now i change the code on the below:

void post_status(RcfClient<I_Interface>* pClient)
{
pClient->post_status(RCF::Oneway, 1, 2, 3);
}

RcfClient<I_Interface>* pClient = new RcfClient<I_Interface>(RCF::TcpEndpoint("127.0.0.1", 12345));
pClient->getClientStub().setConnectTimeoutMs(timeout);
pClient->getClientStub().setRemoteCallTimeoutMs(timeout);

DWORD dwTick = GetTickCount();
while(true)
{
if (GetTickCount() - dwTick >= 1000)
{
post_status(pClient);
dwTick = GetTickCount();
}
Sleep(50);
}

now TIME_WAIT1 is disappear, but TIME_WAIT2 is aleady exist. :twisted:

Re: TCPEndpoint too many TIME_WAIT

Posted: Wed Mar 13, 2019 12:47 am
by jarl
Hi,

This is to be expected when when lots of short-lived TCP connections are being created, and it's due to how TCP is implemented in the operating system. There are various ways to work around it, for example have a read of this:

https://www.fromdual.com/huge-amount-of ... onnections