# Buggy code
def post_fork(self, payload_handler, io_loop):
    """
    After forking we need to create all of the local sockets to listen to the
    router

    :param func payload_handler: A function to called to handle incoming payloads as
                                 they are picked up off the wire
    :param IOLoop io_loop: An instance of a Tornado IOLoop, to handle event scheduling
    """
    self.payload_handler = payload_handler
    self.io_loop = io_loop

    self.context = zmq.Context(1)
    self._socket = self.context.socket(zmq.REP)
    if self.opts.get("ipc_mode", "") == "tcp":
        self.w_uri = "tcp://127.0.0.1:{0}".format(
            self.opts.get("tcp_master_workers", 4515)
        )
    else:
        self.w_uri = "ipc://{0}".format(
            os.path.join(self.opts["sock_dir"], "workers.ipc")
        )
    log.info("Worker binding to socket {0}".format(self.w_uri))
    self._socket.connect(self.w_uri)

    salt.transport.mixins.auth.AESReqServerMixin.post_fork(
        self, payload_handler, io_loop
    )

    self.stream = zmq.eventloop.zmqstream.ZMQStream(self._socket, io_loop=self.io_loop)
    self.stream.on_recv_stream(self.handle_message)


# Traceback (IOError)
2015-12-13 06:53:53,199 [salt.master      ][ERROR   ][17378] Error in function _mine:
Traceback (most recent call last):
File "/usr/lib/python2.7/dist-packages/salt/master.py", line 1379, in run_func
ret = getattr(self, func)(load)
File "/usr/lib/python2.7/dist-packages/salt/master.py", line 1007, in _mine
load = self.__verify_load(load, ('id', 'data', 'tok'))
File "/usr/lib/python2.7/dist-packages/salt/master.py", line 924, in __verify_load
if not self.__verify_minion(load['id'], load['tok']):
File "/usr/lib/python2.7/dist-packages/salt/master.py", line 824, in __verify_minion
with salt.utils.fopen(pub_path, 'r') as fp_:
File "/usr/lib/python2.7/dist-packages/salt/utils/__init__.py", line 1204, in fopen
fhandle = open(*args, **kwargs)
IOError: [Errno 2] No such file or directory: '/etc/salt/pki/master/minions/ause1-encoder546'
2015-12-13 06:54:25,104 [salt.transport.zeromq][ERROR   ][17378] Bad load from minion
2015-12-13 06:54:35,228 [salt.transport.zeromq][ERROR   ][17370] Bad load from minion
2015-12-13 06:54:46,744 [salt.transport.zeromq][ERROR   ][17398] Bad load from minion
2015-12-13 06:54:53,352 [salt.master      ][ERROR   ][17317] Error in function _mine:
Traceback (most recent call last):
File "/usr/lib/python2.7/dist-packages/salt/master.py", line 1379, in run_func
ret = getattr(self, func)(load)
File "/usr/lib/python2.7/dist-packages/salt/master.py", line 1007, in _mine
load = self.__verify_load(load, ('id', 'data', 'tok'))
File "/usr/lib/python2.7/dist-packages/salt/master.py", line 924, in __verify_load
if not self.__verify_minion(load['id'], load['tok']):
File "/usr/lib/python2.7/dist-packages/salt/master.py", line 824, in __verify_minion
with salt.utils.fopen(pub_path, 'r') as fp_:
File "/usr/lib/python2.7/dist-packages/salt/utils/__init__.py", line 1204, in fopen
fhandle = open(*args, **kwargs)
IOError: [Errno 2] No such file or directory: '/etc/salt/pki/master/minions/ause1-encoder546'
2015-12-13 06:55:00,814 [salt.master      ][ERROR   ][17343] Error in function _mine:
Traceback (most recent call last):
File "/usr/lib/python2.7/dist-packages/salt/master.py", line 1379, in run_func
ret = getattr(self, func)(load)
File "/usr/lib/python2.7/dist-packages/salt/master.py", line 1007, in _mine
load = self.__verify_load(load, ('id', 'data', 'tok'))
File "/usr/lib/python2.7/dist-packages/salt/master.py", line 924, in __verify_load
if not self.__verify_minion(load['id'], load['tok']):
File "/usr/lib/python2.7/dist-packages/salt/master.py", line 824, in __verify_minion
with salt.utils.fopen(pub_path, 'r') as fp_:
File "/usr/lib/python2.7/dist-packages/salt/utils/__init__.py", line 1204, in fopen
fhandle = open(*args, **kwargs)
IOError: [Errno 2] No such file or directory: '/etc/salt/pki/master/minions/ause1-encoder646'
2015-12-13 06:55:17,444 [salt.master      ][ERROR   ][17443] Error in function _mine:
Traceback (most recent call last):
File "/usr/lib/python2.7/dist-packages/salt/master.py", line 1379, in run_func
ret = getattr(self, func)(load)
File "/usr/lib/python2.7/dist-packages/salt/master.py", line 1007, in _mine
load = self.__verify_load(load, ('id', 'data', 'tok'))
File "/usr/lib/python2.7/dist-packages/salt/master.py", line 924, in __verify_load
if not self.__verify_minion(load['id'], load['tok']):
File "/usr/lib/python2.7/dist-packages/salt/master.py", line 824, in __verify_minion
with salt.utils.fopen(pub_path, 'r') as fp_:
File "/usr/lib/python2.7/dist-packages/salt/utils/__init__.py", line 1204, in fopen
fhandle = open(*args, **kwargs)
IOError: [Errno 2] No such file or directory: '/etc/salt/pki/master/minions/ause1-encoder66'

# Fixed code
def post_fork(self, payload_handler, io_loop):
    """
    After forking we need to create all of the local sockets to listen to the
    router

    :param func payload_handler: A function to called to handle incoming payloads as
                                 they are picked up off the wire
    :param IOLoop io_loop: An instance of a Tornado IOLoop, to handle event scheduling
    """
    self.payload_handler = payload_handler
    self.io_loop = io_loop

    self.context = zmq.Context(1)
    self._socket = self.context.socket(zmq.REP)
    if HAS_ZMQ_MONITOR and self.opts["zmq_monitor"]:
        # Socket monitor shall be used the only for debug  purposes so using threading doesn't look too bad here
        import threading

        self._w_monitor = ZeroMQSocketMonitor(self._socket)
        t = threading.Thread(target=self._w_monitor.start_poll)
        t.start()

    if self.opts.get("ipc_mode", "") == "tcp":
        self.w_uri = "tcp://127.0.0.1:{0}".format(
            self.opts.get("tcp_master_workers", 4515)
        )
    else:
        self.w_uri = "ipc://{0}".format(
            os.path.join(self.opts["sock_dir"], "workers.ipc")
        )
    log.info("Worker binding to socket {0}".format(self.w_uri))
    self._socket.connect(self.w_uri)

    salt.transport.mixins.auth.AESReqServerMixin.post_fork(
        self, payload_handler, io_loop
    )

    self.stream = zmq.eventloop.zmqstream.ZMQStream(self._socket, io_loop=self.io_loop)
    self.stream.on_recv_stream(self.handle_message)