# Buggy code
def _check_pub_data(self, pub_data):
    """
    Common checks on the pub_data data structure returned from running pub
    """
    if pub_data == "":
        # Failed to authenticate, this could be a bunch of things
        raise EauthAuthenticationError(
            "Failed to authenticate! This is most likely because this "
            "user is not permitted to execute commands, but there is a "
            "small possibility that a disk error occurred (check "
            "disk/inode usage)."
        )

    # Failed to connect to the master and send the pub
    if "error" in pub_data:
        print(pub_data["error"])
        log.debug("_check_pub_data() error: {0}".format(pub_data["error"]))
        return {}
    elif "jid" not in pub_data:
        return {}
    if pub_data["jid"] == "0":
        print("Failed to connect to the Master, is the Salt Master running?")
        return {}

    # If we order masters (via a syndic), don't short circuit if no minions
    # are found
    if not self.opts.get("order_masters"):
        # Check for no minions
        if not pub_data["minions"]:
            print(
                "No minions matched the target. "
                "No command was sent, no jid was assigned."
            )
            return {}
    else:
        self.event.subscribe("syndic/.*/{0}".format(pub_data["jid"]), "regex")

    self.event.subscribe("salt/job/{0}".format(pub_data["jid"]))

    return pub_data


# Traceback (SaltClientError)
2017-03-20 15:58:15,317 [salt.utils.event                         ][DEBUG   ][28048] MasterEvent PUB socket URI: ipc:///var/run/salt/master/master_event_pub.ipc2017-03-20 15:58:15,318 [salt.utils.event                         ][DEBUG   ][28048] MasterEvent PULL socket URI: ipc:///var/run/salt/master/master_event_pull.ipc
Traceback (most recent call last):
File "/usr/lib/python2.6/site-packages/salt/netapi/rest_cherrypy/app.py", line 507, in hypermedia_handler
File "/usr/lib/python2.6/site-packages/cherrypy/_cpdispatch.py", line 34, in __call__
File "/usr/lib/python2.6/site-packages/salt/netapi/rest_cherrypy/app.py", line 933, in POST
File "/usr/lib/python2.6/site-packages/salt/netapi/rest_cherrypy/app.py", line 775, in exec_lowstate
File "/usr/lib/python2.6/site-packages/salt/netapi/__init__.py", line 70, in run
File "/usr/lib/python2.6/site-packages/salt/netapi/__init__.py", line 98, in local
File "/usr/lib/python2.6/site-packages/salt/client/__init__.py", line 535, in cmd
File "/usr/lib/python2.6/site-packages/salt/client/__init__.py", line 290, in run_job
SaltClientError: [Errno 24] Too many open files
2017-03-20 15:58:15,751 [salt.utils.process                       ][INFO    ][28040] Process <function start at 0x1ce6b18> (28048) died with exit status None, restarting...
2017-03-20 15:58:16,757 [salt.utils.process                       ][DEBUG   ][28040] Started 'salt.loaded.int.netapi.rest_cherrypy.start' with pid 20716

# Fixed code
def _check_pub_data(self, pub_data, listen=True):
    """
    Common checks on the pub_data data structure returned from running pub
    """
    if pub_data == "":
        # Failed to authenticate, this could be a bunch of things
        raise EauthAuthenticationError(
            "Failed to authenticate! This is most likely because this "
            "user is not permitted to execute commands, but there is a "
            "small possibility that a disk error occurred (check "
            "disk/inode usage)."
        )

    # Failed to connect to the master and send the pub
    if "error" in pub_data:
        print(pub_data["error"])
        log.debug("_check_pub_data() error: {0}".format(pub_data["error"]))
        return {}
    elif "jid" not in pub_data:
        return {}
    if pub_data["jid"] == "0":
        print("Failed to connect to the Master, is the Salt Master running?")
        return {}

    # If we order masters (via a syndic), don't short circuit if no minions
    # are found
    if not self.opts.get("order_masters"):
        # Check for no minions
        if not pub_data["minions"]:
            print(
                "No minions matched the target. "
                "No command was sent, no jid was assigned."
            )
            return {}

    # don't install event subscription listeners when the request is async
    # and doesn't care. this is important as it will create event leaks otherwise
    if not listen:
        return pub_data

    if self.opts.get("order_masters"):
        self.event.subscribe("syndic/.*/{0}".format(pub_data["jid"]), "regex")

    self.event.subscribe("salt/job/{0}".format(pub_data["jid"]))

    return pub_data