You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@thrift.apache.org by Kyku <kw...@gmail.com> on 2010/03/07 11:29:18 UTC

Closing inactive sockets.

Hello,

Is it possible to set a timeout for server that would close stale
client connections? Normally if a client is shutdown or there's a
communication failure the server's socket for the client will be never
closed leading to loss of resources.

RE: Closing inactive sockets.

Posted by Mark Slee <ms...@facebook.com>.
This is a property of the TServerSocket class.

  void setSendTimeout(int sendTimeout);
  void setRecvTimeout(int recvTimeout);

Those methods set the timeout values for the client sockets that are accepted by the TServerSocket.

The relevant snippet of code is in ::acceptImpl

  shared_ptr<TSocket> client(new TSocket(clientSocket));
  if (sendTimeout_ > 0) {
    client->setSendTimeout(sendTimeout_);
  }
  if (recvTimeout_ > 0) {
    client->setRecvTimeout(recvTimeout_);
  }

So, simply call the setters on the TServerSocket before passing it into your TThreadedServer.

It seems entirely reasonable to add a similar mechanism to TNonblockingServer, I'm surprised it doesn't already exist. The implementation is a little more involved with libevent, but should be pretty straightforward.

Re: DOS concerns it is generally assumed that these servers are intended for deployment in trusted intranet environments, not on the open internet. Still good to have timeouts for playing defense against poorly configured internal clients though.

Cheers,
Mark

-----Original Message-----
From: Kyku [mailto:kwrzalik@gmail.com] 
Sent: Monday, March 08, 2010 12:28 AM
To: thrift-user@incubator.apache.org
Subject: Re: Closing inactive sockets.

Ok, I decided to try TThreadedServer instead. However I don't know how
I can access client sockets to set a timeout on them.

2010/3/7 David Reiss <dr...@facebook.com>:
> Set a read timeout on the server.
>
> If a client is shut down, the OS should still send the FIN packet to
> the server.
>
> Bryan Duxbury wrote:
>> What language are you talking about? I don't believe that Java or Ruby's
>> servers have this weakness.
>>
>> -Bryan
>>
>> On Sun, Mar 7, 2010 at 2:29 AM, Kyku <kw...@gmail.com> wrote:
>>
>>> Hello,
>>>
>>> Is it possible to set a timeout for server that would close stale
>>> client connections? Normally if a client is shutdown or there's a
>>> communication failure the server's socket for the client will be never
>>> closed leading to loss of resources.
>>>
>

Re: Closing inactive sockets.

Posted by Kyku <kw...@gmail.com>.
Ok, I decided to try TThreadedServer instead. However I don't know how
I can access client sockets to set a timeout on them.

2010/3/7 David Reiss <dr...@facebook.com>:
> Set a read timeout on the server.
>
> If a client is shut down, the OS should still send the FIN packet to
> the server.
>
> Bryan Duxbury wrote:
>> What language are you talking about? I don't believe that Java or Ruby's
>> servers have this weakness.
>>
>> -Bryan
>>
>> On Sun, Mar 7, 2010 at 2:29 AM, Kyku <kw...@gmail.com> wrote:
>>
>>> Hello,
>>>
>>> Is it possible to set a timeout for server that would close stale
>>> client connections? Normally if a client is shutdown or there's a
>>> communication failure the server's socket for the client will be never
>>> closed leading to loss of resources.
>>>
>

Re: Closing inactive sockets.

Posted by Kyku <kw...@gmail.com>.
Any plans of implementing it or some workarounds? It's easy to DOS
yours servers this way...

2010/3/7 David Reiss <dr...@facebook.com>:
>> No if you unplug the power/ethernet cable.
> I figured that would fall under the heading of "communication failure".
> I meant if the client program is shut down.
>
> Kyku wrote:
>> Do you mean the server's socket that I create when initializing the
>> server or the client sockets? If the latter, then how do I access them
>> from thrift? I'm using TNonBlockingServer.
> The client sockets.  It looks like we actually don't support this for
> TNonblockingServer.
>
> --David
>

Re: Closing inactive sockets.

Posted by David Reiss <dr...@facebook.com>.
> No if you unplug the power/ethernet cable.
I figured that would fall under the heading of "communication failure".
I meant if the client program is shut down.

Kyku wrote:
> Do you mean the server's socket that I create when initializing the
> server or the client sockets? If the latter, then how do I access them
> from thrift? I'm using TNonBlockingServer.
The client sockets.  It looks like we actually don't support this for
TNonblockingServer.

--David 

Re: Closing inactive sockets.

Posted by Kyku <kw...@gmail.com>.
Do you mean the server's socket that I create when initializing the
server or the client sockets? If the latter, then how do I access them
from thrift? I'm using TNonBlockingServer.

2010/3/7 David Reiss <dr...@facebook.com>:
> Set a read timeout on the server.
>
> If a client is shut down, the OS should still send the FIN packet to
> the server.
>
> Bryan Duxbury wrote:
>> What language are you talking about? I don't believe that Java or Ruby's
>> servers have this weakness.
>>
>> -Bryan
>>
>> On Sun, Mar 7, 2010 at 2:29 AM, Kyku <kw...@gmail.com> wrote:
>>
>>> Hello,
>>>
>>> Is it possible to set a timeout for server that would close stale
>>> client connections? Normally if a client is shutdown or there's a
>>> communication failure the server's socket for the client will be never
>>> closed leading to loss of resources.
>>>
>

Re: Closing inactive sockets.

Posted by Kyku <kw...@gmail.com>.
No if you unplug the power/ethernet cable.

2010/3/7 David Reiss <dr...@facebook.com>:
> Set a read timeout on the server.
>
> If a client is shut down, the OS should still send the FIN packet to
> the server.
>
> Bryan Duxbury wrote:
>> What language are you talking about? I don't believe that Java or Ruby's
>> servers have this weakness.
>>
>> -Bryan
>>
>> On Sun, Mar 7, 2010 at 2:29 AM, Kyku <kw...@gmail.com> wrote:
>>
>>> Hello,
>>>
>>> Is it possible to set a timeout for server that would close stale
>>> client connections? Normally if a client is shutdown or there's a
>>> communication failure the server's socket for the client will be never
>>> closed leading to loss of resources.
>>>
>

Re: Closing inactive sockets.

Posted by David Reiss <dr...@facebook.com>.
Set a read timeout on the server.

If a client is shut down, the OS should still send the FIN packet to
the server.

Bryan Duxbury wrote:
> What language are you talking about? I don't believe that Java or Ruby's
> servers have this weakness.
> 
> -Bryan
> 
> On Sun, Mar 7, 2010 at 2:29 AM, Kyku <kw...@gmail.com> wrote:
> 
>> Hello,
>>
>> Is it possible to set a timeout for server that would close stale
>> client connections? Normally if a client is shutdown or there's a
>> communication failure the server's socket for the client will be never
>> closed leading to loss of resources.
>>

Re: Closing inactive sockets.

Posted by Kyku <kw...@gmail.com>.
I'm talking about C++.

2010/3/7 Bryan Duxbury <br...@rapleaf.com>:
> What language are you talking about? I don't believe that Java or Ruby's
> servers have this weakness.
>
> -Bryan
>
> On Sun, Mar 7, 2010 at 2:29 AM, Kyku <kw...@gmail.com> wrote:
>
>> Hello,
>>
>> Is it possible to set a timeout for server that would close stale
>> client connections? Normally if a client is shutdown or there's a
>> communication failure the server's socket for the client will be never
>> closed leading to loss of resources.
>>
>

Re: Closing inactive sockets.

Posted by Bryan Duxbury <br...@rapleaf.com>.
What language are you talking about? I don't believe that Java or Ruby's
servers have this weakness.

-Bryan

On Sun, Mar 7, 2010 at 2:29 AM, Kyku <kw...@gmail.com> wrote:

> Hello,
>
> Is it possible to set a timeout for server that would close stale
> client connections? Normally if a client is shutdown or there's a
> communication failure the server's socket for the client will be never
> closed leading to loss of resources.
>