[Checkins] SVN: Sandbox/J1m/resumelb/src/zc/resumelb/lb. Handle case of worker disconnection after calling start_response.
Jim Fulton
jim at zope.com
Mon Mar 5 16:28:47 UTC 2012
Log message for revision 124518:
Handle case of worker disconnection after calling start_response.
Changed:
U Sandbox/J1m/resumelb/src/zc/resumelb/lb.py
U Sandbox/J1m/resumelb/src/zc/resumelb/lb.test
-=-
Modified: Sandbox/J1m/resumelb/src/zc/resumelb/lb.py
===================================================================
--- Sandbox/J1m/resumelb/src/zc/resumelb/lb.py 2012-03-05 14:05:01 UTC (rev 124517)
+++ Sandbox/J1m/resumelb/src/zc/resumelb/lb.py 2012-03-05 16:28:45 UTC (rev 124518)
@@ -72,8 +72,6 @@
self.pool.put(worker)
return result
except zc.resumelb.util.Disconnected:
- # XXX need to be more careful about whether
- # start_response was called.
if (int(env.get('CONTENT_LENGTH', 0)) == 0 and
env.get('REQUEST_METHOD') in retry_methods
):
@@ -315,9 +313,9 @@
if data:
logger.debug('yield %r', data)
yield data
- elif data is None:
- raise zc.resumelb.util.Disconnected()
else:
+ if data is None:
+ logger.warning('Disconnected while returning body')
break
finally:
self.end(rno)
Modified: Sandbox/J1m/resumelb/src/zc/resumelb/lb.test
===================================================================
--- Sandbox/J1m/resumelb/src/zc/resumelb/lb.test 2012-03-05 14:05:01 UTC (rev 124517)
+++ Sandbox/J1m/resumelb/src/zc/resumelb/lb.test 2012-03-05 16:28:45 UTC (rev 124518)
@@ -239,8 +239,11 @@
requests are resubmitted to another worker. All other requests
generate a 500 response.
+Also, if a worker has already sent part of the response and
+disconnects, that response is simply truncated.
+
>>> greenlets = []
- >>> for method in ('GET', 'HEAD', 'PUT', 'POST', 'DELETE',
+ >>> for method in ('GET', 'GET', 'HEAD', 'PUT', 'POST', 'DELETE',
... 'OPTIONS', 'TRACE'):
... app = webtest.TestApp(lb.handle_wsgi)
... greenlets.append(
@@ -258,12 +261,19 @@
7 <type 'dict'>
8 <type 'dict'>
9 <type 'dict'>
+ 10 <type 'dict'>
+Now, let's send a partial response from the first GET:
+
+ >>> write_message(worker1, 3, ('200 OK', [
+ ... ('Content-Length', '42'), ('Content-Type', 'text/html')]))
+ >>> gevent.sleep(.01)
+
Now, we'll disconnect worker1:
>>> worker1.close()
-The GET and HEAD request will be send to worker2:
+The second GET and the HEAD request will be send to worker2:
>>> rno1, env1 = read_message(worker2)
>>> rno, blank = read_message(worker2)
@@ -289,6 +299,7 @@
>>> for g in greenlets:
... g.join()
... print repr(g.value)
+ <200 OK text/html no body>
<200 OK text/html body='Hello test\n'>
<200 OK text/html no body>
<502 Bad Gateway text/html body='\n<html><...l>\n'/159>
@@ -297,7 +308,7 @@
<502 Bad Gateway text/html body='\n<html><...l>\n'/159>
<502 Bad Gateway text/html body='\n<html><...l>\n'/159>
- >>> print greenlets[2].value.body
+ >>> print greenlets[3].value.body
<BLANKLINE>
<html><meta http-equiv="refresh" content="1"><body>
The server was unable to handle your request due to a transient failure.
@@ -401,7 +412,7 @@
>>> len(lb.pool.workers)
2
-Because the lb didn't reconnect, out's socket is till the one from
+Because the lb didn't reconnect, our's socket is till the one from
before that we closed:
>>> out.socket is outsocket
More information about the checkins
mailing list