summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLauren Perry <lauren.perry@codethink.co.uk>2015-01-20 11:48:05 +0000
committerLauren Perry <lauren.perry@codethink.co.uk>2015-02-09 16:01:20 +0000
commit0563ed23dedd5dc8422e2407b01ca5ade040f051 (patch)
treee483d381723ab9c50d7f86d98fecd29909331189
parentf0c5d4c0ef35cc43aa059cd2255e41c60c4cac77 (diff)
downloadmorph-0563ed23dedd5dc8422e2407b01ca5ade040f051.tar.gz
Fix distbuild controller crashing on some invalid inputs
-rw-r--r--distbuild/initiator_connection.py22
-rw-r--r--distbuild/jm.py9
2 files changed, 20 insertions, 11 deletions
diff --git a/distbuild/initiator_connection.py b/distbuild/initiator_connection.py
index db982230..9dbca397 100644
--- a/distbuild/initiator_connection.py
+++ b/distbuild/initiator_connection.py
@@ -100,15 +100,19 @@ class InitiatorConnection(distbuild.StateMachine):
logging.debug('InitiatorConnection: from %s: %r', self.initiator_name,
event.msg)
- if event.msg['type'] == 'build-request':
- new_id = self._idgen.next()
- self.our_ids.add(new_id)
- self._route_map.add(event.msg['id'], new_id)
- event.msg['id'] = new_id
- build_controller = distbuild.BuildController(
- self, event.msg, self.artifact_cache_server,
- self.morph_instance)
- self.mainloop.add_state_machine(build_controller)
+ try:
+ if event.msg['type'] == 'build-request':
+ new_id = self._idgen.next()
+ self.our_ids.add(new_id)
+ self._route_map.add(event.msg['id'], new_id)
+ event.msg['id'] = new_id
+ build_controller = distbuild.BuildController(
+ self, event.msg, self.artifact_cache_server,
+ self.morph_instance)
+ self.mainloop.add_state_machine(build_controller)
+ except (KeyError, ValueError) as ex:
+ logging.error('Invalid message from initiator: %s: exception %s',
+ event.msg, ex)
def _disconnect(self, event_source, event):
for id in self.our_ids:
diff --git a/distbuild/jm.py b/distbuild/jm.py
index 615100e4..ebdcfbf8 100644
--- a/distbuild/jm.py
+++ b/distbuild/jm.py
@@ -109,8 +109,13 @@ class JsonMachine(StateMachine):
line = line.rstrip()
if self.debug_json:
logging.debug('JsonMachine: line: %s' % repr(line))
- msg = yaml.load(json.loads(line))
- self.mainloop.queue_event(self, JsonNewMessage(msg))
+ msg = None
+ try:
+ msg = yaml.safe_load(json.loads(line))
+ except Exception:
+ logging.error('Invalid input: %s' % line)
+ if msg:
+ self.mainloop.queue_event(self, JsonNewMessage(msg))
def _send_eof(self, event_source, event):
self.mainloop.queue_event(self, JsonEof())