def _handle_stranded_msgs(self, eid, uuid):
outstanding = self.queues[eid]<EOL>for msg_id in outstanding:<EOL><INDENT>self.pending.remove(msg_id)<EOL>self.all_completed.add(msg_id)<EOL>try:<EOL><INDENT>raise error.EngineError("<STR_LIT>" % (eid, msg_id))<EOL><DEDENT>except:<EOL><INDENT>content = error.wrap_exception()<EOL><DEDENT>header = {}<EOL>header['<STR_LIT>'] = uuid<EOL>header['<STR_LIT:date>'] = datetime.now()<EOL>rec = dict(result_content=content, result_header=header, result_buffers=[])<EOL>rec['<STR_LIT>'] = header['<STR_LIT:date>']<EOL>rec['<STR_LIT>'] = uuid<EOL>try:<EOL><INDENT>self.db.update_record(msg_id, rec)<EOL><DEDENT>except Exception:<EOL><INDENT>self.log.error("<STR_LIT>", msg_id, exc_info=True)<EOL><DEDENT><DEDENT>
Handle messages known to be on an engine when the engine unregisters.

        It is possible that this will fire prematurely - that is, an engine will
        go down after completing a result, and the client will be notified
        that the result failed and later receive the actual result.