core: Handle unpicklable data in dispatch_calls()

Sending just via .call_async() would previously crash the child, now it
generates CallError like intended.
wip-fakessh-exit-status
David Wilson 7 years ago
parent 6d403481d4
commit 5855f1739f

@ -1330,15 +1330,13 @@ class ExternalContext(object):
finally: finally:
fp.close() fp.close()
def _dispatch_calls(self): def _dispatch_one(self, msg):
for msg in self.channel:
data = msg.unpickle(throw=False) data = msg.unpickle(throw=False)
_v and LOG.debug('_dispatch_calls(%r)', data) _v and LOG.debug('_dispatch_calls(%r)', data)
if msg.auth_id not in mitogen.parent_ids: if msg.auth_id not in mitogen.parent_ids:
LOG.warning('CALL_FUNCTION from non-parent %r', msg.auth_id) LOG.warning('CALL_FUNCTION from non-parent %r', msg.auth_id)
modname, klass, func, args, kwargs = data modname, klass, func, args, kwargs = data
try:
obj = __import__(modname, {}, {}, ['']) obj = __import__(modname, {}, {}, [''])
if klass: if klass:
obj = getattr(obj, klass) obj = getattr(obj, klass)
@ -1347,7 +1345,12 @@ class ExternalContext(object):
kwargs.setdefault('econtext', self) kwargs.setdefault('econtext', self)
if getattr(fn, 'mitogen_takes_router', None): if getattr(fn, 'mitogen_takes_router', None):
kwargs.setdefault('router', self.router) kwargs.setdefault('router', self.router)
msg.reply(fn(*args, **kwargs)) return fn(*args, **kwargs)
def _dispatch_calls(self):
for msg in self.channel:
try:
msg.reply(self._dispatch_one(msg))
except Exception, e: except Exception, e:
_v and LOG.debug('_dispatch_calls: %s', e) _v and LOG.debug('_dispatch_calls: %s', e)
msg.reply(CallError(e)) msg.reply(CallError(e))

Loading…
Cancel
Save