# Buggy code
def process_request(self, request, client_address):
    """Override of TCPServer.process_request() that provides for forking request handlers and
    delegates error handling to the request handler."""
    # Instantiate the request handler.
    handler = self.RequestHandlerClass(request, client_address, self)

    try:
        # Attempt to handle a request with the handler.
        handler.handle_request()
    except Exception as e:
        # If that fails, (synchronously) handle the error with the error handler sans-fork.
        try:
            handler.handle_error(e)
        finally:
            # Shutdown the socket since we don't expect a fork() in the exception context.
            self.shutdown_request(request)
    else:
        # At this point, we expect a fork() has taken place - the parent side will return, and so we
        # close the request here from the parent without explicitly shutting down the socket. The
        # child half of this will perform an os._exit() before it gets to this point and is also
        # responsible for shutdown and closing of the socket when its execution is complete.
        self.close_request(request)


# 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 process_request(self, request, client_address):
    """Override of TCPServer.process_request() that provides for forking request handlers and
    delegates error handling to the request handler."""
    # Instantiate the request handler.
    handler = self.RequestHandlerClass(request, client_address, self)

    try:
        # Attempt to handle a request with the handler under the context_lock.
        with self._context_lock():
            handler.handle_request()
    except Exception as e:
        # If that fails, (synchronously) handle the error with the error handler sans-fork.
        try:
            handler.handle_error(e)
        finally:
            # Shutdown the socket since we don't expect a fork() in the exception context.
            self.shutdown_request(request)
    else:
        # At this point, we expect a fork() has taken place - the parent side will return, and so we
        # close the request here from the parent without explicitly shutting down the socket. The
        # child half of this will perform an os._exit() before it gets to this point and is also
        # responsible for shutdown and closing of the socket when its execution is complete.
        self.close_request(request)