# Buggy code
def __init__(
    self, server_address, runner_factory, handler_class=None, bind_and_activate=True
):
    """Override of TCPServer.__init__().

    N.B. the majority of this function is copied verbatim from TCPServer.__init__().

    :param tuple server_address: An address tuple of (hostname, port) for socket.bind().
    :param class runner_factory: A factory function for creating a DaemonPantsRunner for each run.
    :param class handler_class: The request handler class to use for each request. (Optional)
    :param bool bind_and_activate: If True, binds and activates networking at __init__ time.
                                   (Optional)
    """
    # Old-style class, so we must invoke __init__() this way.
    BaseServer.__init__(self, server_address, handler_class or PailgunHandler)
    self.socket = RecvBufferedSocket(
        socket.socket(self.address_family, self.socket_type)
    )
    self.runner_factory = runner_factory
    self.allow_reuse_address = True  # Allow quick reuse of TCP_WAIT sockets.
    self.server_port = None  # Set during server_bind() once the port is bound.

    if bind_and_activate:
        try:
            self.server_bind()
            self.server_activate()
        except Exception:
            self.server_close()
            raise


# Traceback (AttributeError)
W0602 21:35:21.260252 22326 pailgun_service.py:69] encountered exception during SchedulerService.get_build_graph():
Traceback (most recent call last):
File "/home/travis/build/pantsbuild/pants/src/python/pants/pantsd/service/pailgun_service.py", line 65, in runner_factory
build_graph = self._scheduler_service.get_build_graph(spec_roots)
File "/home/travis/build/pantsbuild/pants/src/python/pants/pantsd/service/scheduler_service.py", line 84, in get_build_graph
return self._graph_helper.create_graph(spec_roots)
File "/home/travis/build/pantsbuild/pants/src/python/pants/bin/engine_initializer.py", line 64, in create_graph
for _ in graph.inject_specs_closure(spec_roots):  # Ensure the entire generator is unrolled.
File "/home/travis/build/pantsbuild/pants/src/python/pants/engine/legacy/graph.py", line 169, in inject_specs_closure
for address in self._inject(specs):
File "/home/travis/build/pantsbuild/pants/src/python/pants/engine/legacy/graph.py", line 185, in _inject
entries = maybe_list(state.value, expected_type=LegacyTarget)
AttributeError: 'NoneType' object has no attribute 'value'

# Fixed code
def __init__(
    self,
    server_address,
    runner_factory,
    context_lock,
    handler_class=None,
    bind_and_activate=True,
):
    """Override of TCPServer.__init__().

    N.B. the majority of this function is copied verbatim from TCPServer.__init__().

    :param tuple server_address: An address tuple of (hostname, port) for socket.bind().
    :param class runner_factory: A factory function for creating a DaemonPantsRunner for each run.
    :param func context_lock: A contextmgr that will be used as a lock during request handling/forking.
    :param class handler_class: The request handler class to use for each request. (Optional)
    :param bool bind_and_activate: If True, binds and activates networking at __init__ time.
                                   (Optional)
    """
    # Old-style class, so we must invoke __init__() this way.
    BaseServer.__init__(self, server_address, handler_class or PailgunHandler)
    self.socket = RecvBufferedSocket(
        socket.socket(self.address_family, self.socket_type)
    )
    self.runner_factory = runner_factory
    self.allow_reuse_address = True  # Allow quick reuse of TCP_WAIT sockets.
    self.server_port = None  # Set during server_bind() once the port is bound.
    self._context_lock = context_lock

    if bind_and_activate:
        try:
            self.server_bind()
            self.server_activate()
        except Exception:
            self.server_close()
            raise