[z3-checkins] r51116 - z3/deliverance/DeliveranceVHoster/trunk/dvhoster
ejucovy at codespeak.net
ejucovy at codespeak.net
Tue Jan 29 20:48:35 CET 2008
Author: ejucovy
Date: Tue Jan 29 20:48:33 2008
New Revision: 51116
Modified:
z3/deliverance/DeliveranceVHoster/trunk/dvhoster/dispatcher.py
z3/deliverance/DeliveranceVHoster/trunk/dvhoster/socket_error.py
Log:
retry after one second on socket error before giving up and throwing http gateway timeout
Modified: z3/deliverance/DeliveranceVHoster/trunk/dvhoster/dispatcher.py
==============================================================================
--- z3/deliverance/DeliveranceVHoster/trunk/dvhoster/dispatcher.py (original)
+++ z3/deliverance/DeliveranceVHoster/trunk/dvhoster/dispatcher.py Tue Jan 29 20:48:33 2008
@@ -10,6 +10,7 @@
from wsgifilter import relocateresponse
from deliverance.wsgimiddleware import DeliveranceMiddleware
from dvhoster.socket_error import SocketErrorToHTTPServerException
+from dvhoster.socket_error import RetryOnceOnSocketError
from dvhoster.model import DomainInfoSet, DomainInfoApp
from dvhoster import current_environ
from dvhoster.debuginterp import Renderer
@@ -181,6 +182,7 @@
tasklist=self.transcluder_pool,
include_predicate=self.transcluder_ok_hosts,
recursion_predicate=self.transcluder_ok_hosts)
+ app = RetryOnceOnSocketError(app)
app = SocketErrorToHTTPServerException(app)
if should_theme_uri:
Modified: z3/deliverance/DeliveranceVHoster/trunk/dvhoster/socket_error.py
==============================================================================
--- z3/deliverance/DeliveranceVHoster/trunk/dvhoster/socket_error.py (original)
+++ z3/deliverance/DeliveranceVHoster/trunk/dvhoster/socket_error.py Tue Jan 29 20:48:33 2008
@@ -1,4 +1,5 @@
import socket
+import time
from paste.httpexceptions import HTTPGatewayTimeout
class SocketErrorToHTTPServerException(object):
@@ -8,5 +9,17 @@
def __call__(self, environ, start_response):
try:
return self.app(environ, start_response)
+ except socket.error, e:
+ raise HTTPGatewayTimeout("Socket error %d - %r" % e.args)
+
+class RetryOnceOnSocketError(object):
+ def __init__(self, app):
+ self.app = app
+
+ def __call__(self, environ, start_response):
+ try:
+ return self.app(environ, start_response)
except socket.error:
- raise HTTPGatewayTimeout
+ # Give the remote service a second to restart, etc.
+ time.sleep(1)
+ return self.app(environ, start_response)
More information about the z3-checkins
mailing list