Skip to content

Commit

Permalink
Added test case for parsing errors during XML-RPC request decode. Fixed
Browse files Browse the repository at this point in the history
problems with XML-RPC dispatch after request parsing errors; the previous
implementation never dispatched a result causing clients to block until
their timeout and potential resource exhaustion in the server.
  • Loading branch information
chris-allan authored and joshmarshall committed Nov 18, 2010
1 parent 899c087 commit fda3e0e
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 4 deletions.
15 changes: 13 additions & 2 deletions tests/xml.py
@@ -1,5 +1,6 @@
import unittest
import xmlrpclib
import urllib2
import time
import threading
from tornadorpc.xml import XMLRPCHandler
Expand Down Expand Up @@ -73,9 +74,12 @@ class RPCTests(object):

def setUp(self):
server = TestServer.start(self.handler, self.port)


def get_url(self):
return 'http://localhost:%d' % self.port

def get_client(self):
client = xmlrpclib.ServerProxy('http://localhost:%d' % self.port)
client = xmlrpclib.ServerProxy(self.get_url())
return client

def test_tree(self):
Expand Down Expand Up @@ -128,6 +132,13 @@ def test_internal_error(self):
except xmlrpclib.Fault, f:
self.assertEqual(-32603, f.faultCode)

def test_parse_error(self):
try:
print self.get_url()
urllib2.urlopen(self.get_url(), '<garbage/>')
except xmlrpclib.Fault, f:
self.assertEqual(-32700, f.faultCode)

def test_handler_return_fault(self):
client = self.get_client()
fault_code = 100
Expand Down
9 changes: 7 additions & 2 deletions tornadorpc/base.py
Expand Up @@ -79,16 +79,21 @@ def run(self, handler, request_body):
requests = self.parse_request(request_body)
except:
self.traceback()
return self.faults.parse_error()
return self.handler.result(self.faults.parse_error())
if type(requests) is not types.TupleType:
# SHOULD be the result of a fault call,
# according tothe parse_request spec below.
if type(requests) in types.StringTypes:
# Should be the response text of a fault
return requests
elif 'response' in dir(requests):
elif hasattr(requests, 'response'):
# Fault types should have a 'response' method
return requests.response()
elif hasattr(requests, 'faultCode'):
# XML-RPC fault types need to be properly dispatched. This
# should only happen if there was an error parsing the
# request above.
return self.handler.result(requests)
else:
# No idea, hopefully the handler knows what it
# is doing.
Expand Down

0 comments on commit fda3e0e

Please sign in to comment.