Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
Immediately detecting lost connections in HTTPServer
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  6 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
eestolano  
View profile  
 More options Aug 28 2012, 2:09 pm
From: eestolano <eestol...@gmail.com>
Date: Tue, 28 Aug 2012 11:09:32 -0700 (PDT)
Local: Tues, Aug 28 2012 2:09 pm
Subject: Immediately detecting lost connections in HTTPServer

Hi,

I'm trying to create an HTTP server (using HTTPServer) that works as follows:

- Clients connect to the server with a large timeout (around 5 minutes).
- The server may have a reply for them immediately, or later (hence the large timeout).
- Sometimes, the server will not have a reply in time; the client will disconnect.

Here's the part I haven't been able to figure out: how can I make the handler detect the client timeout *when it happens*? If I catch the exception when the handler tries to reply and fails, that could be minutes after the client disconnected.

Thanks!

    ~ Esteban


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Matthias Urlichs  
View profile  
 More options Aug 28 2012, 5:17 pm
From: Matthias Urlichs <matth...@urlichs.de>
Date: Tue, 28 Aug 2012 23:16:21 +0200
Local: Tues, Aug 28 2012 5:16 pm
Subject: Re: [gevent] Immediately detecting lost connections in HTTPServer
Hi,

eestolano:

> Here's the part I haven't been able to figure out: how can I make the handler detect the client timeout *when it happens*?

The client's socket becomes readable; actually reading from it yields EOF.

--
-- Matthias Urlichs


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
eestolano  
View profile  
 More options Aug 28 2012, 5:44 pm
From: eestolano <eestol...@gmail.com>
Date: Tue, 28 Aug 2012 14:44:57 -0700 (PDT)
Local: Tues, Aug 28 2012 5:44 pm
Subject: Re: [gevent] Immediately detecting lost connections in HTTPServer

Thanks! I'm not sure how to do that, though. I'm aiming for something like this (omitting the queue-producer code):

--------
def handle(request): # gevent.core.http_connection                                                                                                                                                                                                          

    ### Wait for another greenlet to put an item on a queue

    request.send_reply(200, 'OK', item_from_queue)

def main():

    ### launch separate greenlet to put items on queue

    # set up web server                                                                                                                                                                                                                    
    server = HTTPServer(('0.0.0.0', 10545), handle)
    print "Serving on port 10545."
    server.serve_forever()

--------

I was hoping HTTPServer would allow for a connection loss handler, but it doesn't seem to.

I'm not sure how to implement your suggestion for two reasons:

- How can I access the socket from the gevent.core.http_connection object? I can't find anything in the docs.
- If I can get to the socket, does this mean I have to poll the socket periodically for EOF? I'd rather avoid polling.

Any suggestions?

Thanks!

    ~ Esteban


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Alexandre Kandalintsev  
View profile  
 More options Aug 29 2012, 5:29 am
From: Alexandre Kandalintsev <s...@messir.net>
Date: Wed, 29 Aug 2012 11:29:06 +0200
Local: Wed, Aug 29 2012 5:29 am
Subject: Re: [gevent] Immediately detecting lost connections in HTTPServer
Tune tcp keepalive timeouts. This will help with long timeouts. May be
it's possible to do that on per-socket basis.

--
Alexandre Kandalintsev


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Matthias Urlichs  
View profile  
 More options Aug 29 2012, 6:02 am
From: Matthias Urlichs <matth...@urlichs.de>
Date: Wed, 29 Aug 2012 12:01:29 +0200
Local: Wed, Aug 29 2012 6:01 am
Subject: Re: [gevent] Immediately detecting lost connections in HTTPServer
Hi,

Alexandre Kandalintsev:

> Tune tcp keepalive timeouts. This will help with long timeouts.

TCP keepalives exist for the purpose of auto-closing sockets whose remote
side becomes unreacheable / crashes instead of closing the connection.
They don't indicate to your application that a socket is closed.

If you don't read from (or write to) the socket, you won't notice either.

If you want a notification, you need to select() the socket.

--
-- Matthias Urlichs


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Executier Godlike  
View profile  
 More options Aug 29 2012, 6:54 am
From: Executier Godlike <s...@messir.net>
Date: Wed, 29 Aug 2012 12:54:33 +0200
Local: Wed, Aug 29 2012 6:54 am
Subject: Re: [gevent] Immediately detecting lost connections in HTTPServer
> If you want a notification, you need to select() the socket.

Whoops, I thought the problem is to detect dead clients...

 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »