# Buggy code
def Analyze(self, hashes):
    """Looks up hashes in nsrlsvr.

    Args:
      hashes (list[str]): hash values to look up.

    Returns:
      list[HashAnalysis]: analysis results, or an empty list on error.
    """
    # Open a socket
    logging.debug("Opening connection to {0:s}:{1:d}".format(self._host, self._port))
    try:
        nsrl_socket = socket.create_connection(
            (self._host, self._port), self._SOCKET_TIMEOUT
        )
    except socket.error as exception:
        logging.error(
            (
                "Error communicating with nsrlsvr {0:s}. nsrlsvr plugin is aborting."
            ).format(exception)
        )
        self.SignalAbort()
        return []

    hash_analyses = []
    for digest in hashes:
        query = "QUERY {0:s}\n".format(digest)
        try:
            nsrl_socket.sendall(query)
            response = nsrl_socket.recv(self._RECEIVE_BUFFER_SIZE)
        except socket.error as exception:
            logging.error(
                (
                    "Error communicating with nsrlsvr {0:s}. nsrlsvr plugin is "
                    "aborting."
                ).format(exception)
            )
            self.SignalAbort()
            return hash_analyses

        _, _, nsrl_result = response.rpartition(" ")

        if nsrl_result == "1":
            hash_analysis = interface.HashAnalysis(digest, True)
            hash_analyses.append(hash_analysis)
        else:
            hash_analysis = interface.HashAnalysis(digest, False)
            hash_analyses.append(hash_analysis)
    nsrl_socket.close()

    return hash_analyses


# Traceback (KeyError)
[ERROR] (nsrlsvr   ) PID:XXXXX <analysis_process> <dfvfs.path.os_path_spec.OSPathSpec object at 0xXXXXXXXXXXXX>
Traceback (most recent call last):
File "/usr/lib/python2.7/dist-packages/plaso/multi_processing/analysis_process.py", line 138, in _Main
self._analysis_mediator.ProduceAnalysisReport(self._analysis_plugin)
File "/usr/lib/python2.7/dist-packages/plaso/analysis/mediator.py", line 95, in ProduceAnalysisReport
analysis_report = plugin.CompileReport(self)
File "/usr/lib/python2.7/dist-packages/plaso/analysis/interface.py", line 280, in CompileReport
hash_analysis)
File "/usr/lib/python2.7/dist-packages/plaso/analysis/interface.py", line 187, in _HandleHashAnalysis
event_uuids = self._event_uuids_by_pathspec.pop(pathspec)
KeyError: <dfvfs.path.os_path_spec.OSPathSpec object at 0xXXXXXXXXXXXX>

# Fixed code
def Analyze(self, hashes):
    """Looks up hashes in nsrlsvr.

    Args:
      hashes (list[str]): hash values to look up.

    Returns:
      list[HashAnalysis]: analysis results, or an empty list on error.
    """
    logging.debug("Opening connection to {0:s}:{1:d}".format(self._host, self._port))

    nsrl_socket = self._GetSocket()
    if not nsrl_socket:
        self.SignalAbort()
        return []

    hash_analyses = []
    for digest in hashes:
        response = self._QueryHash(nsrl_socket, digest)
        if response is None:
            continue

        hash_analysis = interface.HashAnalysis(digest, response)
        hash_analyses.append(hash_analysis)

    nsrl_socket.close()

    logging.debug("Closed connection to {0:s}:{1:d}".format(self._host, self._port))

    return hash_analyses