Commit f44e62b1 authored by Vincent Pelletier's avatar Vincent Pelletier

When xmlrpc uses expat, catch one more exception type in safeRpcCall.

parent 509719bb
...@@ -43,6 +43,20 @@ DEFAULT_SLEEP_TIMEOUT = 120 # time in seconds to sleep ...@@ -43,6 +43,20 @@ DEFAULT_SLEEP_TIMEOUT = 120 # time in seconds to sleep
supervisord_pid_file = None supervisord_pid_file = None
# XXX: below section is shared with product/ERP5Type/tests/runTestSuite.py .
# They are supposed to be merged into a common library/tool someday, until
# then please keep them synchronised.
# Depending on used xmlrpc backend, different exceptions can be thrown.
SAFE_RPC_EXCEPTION_LIST = [socket.error, xmlrpclib.ProtocolError, xmlrpclib.Fault]
parser, _ = xmlrpclib.getparser()
if xmlrpclib.ExpatParser and isinstance(parser, xmlrpclib.ExpatParser):
SAFE_RPC_EXCEPTION_LIST.append(xmlrpclib.expat.ExpatError)
else:
print >>sys.stderr, 'Warning: unhandled xmlrpclib parser %r, some ' \
'exceptions might get through safeRpcCall' % (parser, )
SAFE_RPC_EXCEPTION_LIST = tuple(SAFE_RPC_EXCEPTION_LIST)
del parser, _
def safeRpcCall(log, proxy, function_id, retry, *args): def safeRpcCall(log, proxy, function_id, retry, *args):
# this method will try infinitive calls to backend # this method will try infinitive calls to backend
# this can cause testnode to looked "stalled" # this can cause testnode to looked "stalled"
...@@ -54,7 +68,7 @@ def safeRpcCall(log, proxy, function_id, retry, *args): ...@@ -54,7 +68,7 @@ def safeRpcCall(log, proxy, function_id, retry, *args):
log('safeRpcCall called with method : %s' % function_id) log('safeRpcCall called with method : %s' % function_id)
function = getattr(proxy, function_id) function = getattr(proxy, function_id)
return function(*args) return function(*args)
except (socket.error, xmlrpclib.ProtocolError, xmlrpclib.Fault), e: except SAFE_RPC_EXCEPTION_LIST, e:
log('Exception in safeRpcCall when trying %s with %r' % (function_id, args), log('Exception in safeRpcCall when trying %s with %r' % (function_id, args),
exc_info=sys.exc_info()) exc_info=sys.exc_info())
if not(retry): if not(retry):
......
...@@ -3,7 +3,18 @@ import argparse, pprint, socket, sys, time, xmlrpclib ...@@ -3,7 +3,18 @@ import argparse, pprint, socket, sys, time, xmlrpclib
from DummyTaskDistributionTool import DummyTaskDistributionTool from DummyTaskDistributionTool import DummyTaskDistributionTool
from ERP5TypeTestSuite import ERP5TypeTestSuite from ERP5TypeTestSuite import ERP5TypeTestSuite
# XXX: below section is shared with erp5/util/testnode/testnode.py .
# They are supposed to be merged into a common library/tool someday, until
# then please keep them synchronised.
# Depending on used xmlrpc backend, different exceptions can be thrown.
SAFE_RPC_EXCEPTION_LIST = [socket.error, xmlrpclib.ProtocolError, xmlrpclib.Fault]
parser, _ = xmlrpclib.getparser() parser, _ = xmlrpclib.getparser()
if xmlrpclib.ExpatParser and isinstance(parser, xmlrpclib.ExpatParser):
SAFE_RPC_EXCEPTION_LIST.append(xmlrpclib.expat.ExpatError)
else:
print >>sys.stderr, 'Warning: unhandled xmlrpclib parser %r, some ' \
'exceptions might get through safeRpcCall' % (parser, )
SAFE_RPC_EXCEPTION_LIST = tuple(SAFE_RPC_EXCEPTION_LIST)
parser_klass = parser.__class__ parser_klass = parser.__class__
__original_feed = parser_klass.feed __original_feed = parser_klass.feed
def verbose_feed(self, data): def verbose_feed(self, data):
...@@ -56,7 +67,7 @@ def safeRpcCall(function, *args): ...@@ -56,7 +67,7 @@ def safeRpcCall(function, *args):
while True: while True:
try: try:
return function(*xmlrpc_arg_list) return function(*xmlrpc_arg_list)
except (socket.error, xmlrpclib.ProtocolError, xmlrpclib.Fault), e: except SAFE_RPC_EXCEPTION_LIST, e:
print >>sys.stderr, e print >>sys.stderr, e
pprint.pprint(args, file(function._Method__name, 'w')) pprint.pprint(args, file(function._Method__name, 'w'))
time.sleep(retry) time.sleep(retry)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment