# Buggy code
def get_load(jid):
    """
    Return the load data that marks a specified jid
    """
    jid_dir = salt.utils.jid.jid_dir(jid, _job_dir(), __opts__["hash_type"])
    load_fn = os.path.join(jid_dir, LOAD_P)
    if not os.path.exists(jid_dir) or not os.path.exists(load_fn):
        return {}
    serial = salt.payload.Serial(__opts__)
    ret = {}
    with salt.utils.files.fopen(os.path.join(jid_dir, LOAD_P), "rb") as rfh:
        ret = serial.load(rfh)
    if ret is None:
        ret = {}
    minions_cache = [os.path.join(jid_dir, MINIONS_P)]
    minions_cache.extend(glob.glob(os.path.join(jid_dir, SYNDIC_MINIONS_P.format("*"))))
    all_minions = set()
    for minions_path in minions_cache:
        log.debug("Reading minion list from %s", minions_path)
        try:
            with salt.utils.files.fopen(minions_path, "rb") as rfh:
                all_minions.update(serial.load(rfh))
        except IOError as exc:
            salt.utils.files.process_read_exception(exc, minions_path)

    if all_minions:
        ret["Minions"] = sorted(all_minions)

    return ret


# Traceback (UnpackValueError)
03:55:54   test_multiple_sources_master_dev_merge_lists (integration.pillar.test_git_pillar.TestGitPythonAuthenticatedHTTP)

03:55:55 03:55:54,575 [salt.payload                               :147 ][CRITICAL] Could not deserialize msgpack message. This often happens when trying to read a file not in binary mode. To see message payload, enable debug logging and retry. Exception: Unpack failed: error = 0
03:55:55 03:55:54,686 [tornado.application                        :611 ][ERROR   ] Exception in callback <functools.partial object at 0xbd5edb8>
03:55:55 Traceback (most recent call last):
03:55:55   File "/usr/lib64/python2.7/site-packages/tornado/ioloop.py", line 591, in _run_callback
03:55:55     ret = callback()
03:55:55   File "/usr/lib64/python2.7/site-packages/tornado/stack_context.py", line 274, in null_wrapper
03:55:55     return fn(*args, **kwargs)
03:55:55   File "/testing/salt/minion.py", line 3139, in _process_event
03:55:55     self.mminion.returners[fstr](data['jid'])
03:55:55   File "/testing/salt/returners/local_cache.py", line 300, in get_load
03:55:55     ret = serial.load(rfh)
03:55:55   File "/testing/salt/payload.py", line 166, in load
03:55:55     return self.loads(data)
03:55:55   File "/testing/salt/payload.py", line 137, in loads
03:55:55     ret = msgpack.loads(msg, use_list=True, encoding=encoding)
03:55:55   File "msgpack/_unpacker.pyx", line 210, in msgpack._unpacker.unpackb
03:55:55 UnpackValueError: Unpack failed: error = 0

03:56:08 [CPU:0.0%|MEM:35.7%]  ... OK (14.152s)

# Fixed code
def get_load(jid):
    """
    Return the load data that marks a specified jid
    """
    jid_dir = salt.utils.jid.jid_dir(jid, _job_dir(), __opts__["hash_type"])
    load_fn = os.path.join(jid_dir, LOAD_P)
    if not os.path.exists(jid_dir) or not os.path.exists(load_fn):
        return {}
    serial = salt.payload.Serial(__opts__)
    ret = {}
    load_p = os.path.join(jid_dir, LOAD_P)
    num_tries = 5
    for index in range(1, num_tries + 1):
        with salt.utils.files.fopen(load_p, "rb") as rfh:
            try:
                ret = serial.load(rfh)
                break
            except Exception as exc:
                if index == num_tries:
                    time.sleep(0.25)
    else:
        log.critical("Failed to unpack %s", load_p)
        raise exc
    if ret is None:
        ret = {}
    minions_cache = [os.path.join(jid_dir, MINIONS_P)]
    minions_cache.extend(glob.glob(os.path.join(jid_dir, SYNDIC_MINIONS_P.format("*"))))
    all_minions = set()
    for minions_path in minions_cache:
        log.debug("Reading minion list from %s", minions_path)
        try:
            with salt.utils.files.fopen(minions_path, "rb") as rfh:
                all_minions.update(serial.load(rfh))
        except IOError as exc:
            salt.utils.files.process_read_exception(exc, minions_path)

    if all_minions:
        ret["Minions"] = sorted(all_minions)

    return ret