# Buggy code
def stop_component(self, component_id, details=None):
    """
    Stop a component currently running within this container.

    :param component_id: The ID of the component to stop.
    :type component_id: int

    :param details: Caller details.
    :type details: instance of :class:`autobahn.wamp.types.CallDetails`

    :returns: Stop information.
    :rtype: dict
    """
    self.log.debug(
        "{klass}.stop_component({component_id}, {details})",
        klass=self.__class__.__name__,
        component_id=component_id,
        details=details,
    )

    if component_id not in self.components:
        raise ApplicationError(
            "crossbar.error.no_such_object",
            "no component with ID {} running in this container".format(component_id),
        )

    component = self.components[component_id]

    try:
        component.proto.close()
    except:
        self.log.failure(
            "failed to close protocol on component '{component_id}': {log_failure}",
            component_id=component_id,
        )
        raise
    else:
        # essentially just waiting for "on_component_stop"
        yield component._stopped

    stopped = {
        "component_id": component_id,
        "uptime": (datetime.utcnow() - component.started).total_seconds(),
        "caller": {
            "session": details.caller,
            "authid": details.caller_authid,
            "authrole": details.caller_authrole,
        },
    }

    # the component.proto above normally already cleaned it up
    if component_id in self.components:
        del self.components[component_id]

    # FIXME: this is getting autobahn.wamp.exception.TransportLost
    if False:
        self.publish(
            "{}.on_component_stopped".format(self._uri_prefix),
            stopped,
            options=PublishOptions(exclude=details.caller),
        )

    returnValue(stopped)


# Traceback (builtins.AssertionError)
2017-09-05T14:52:34+0200 [Controller  15960] Starting 2 workers ...
2017-09-05T14:52:34+0200 [Controller  15960] Router worker "worker-001" starting ..
2017-09-05T14:52:34+0200 [Router      15969] Started Router worker "worker-001" [crossbar.worker.router.RouterWorkerSession / CPython-EPollReactor]
2017-09-05T14:52:34+0200 [Router      15969] Router worker "worker-001" session 3303279962187294 initializing ..
2017-09-05T14:52:34+0200 [Router      15969] Registered 35 procedures
2017-09-05T14:52:34+0200 [Router      15969] Router worker "worker-001" session ready
2017-09-05T14:52:34+0200 [Controller  15960] Router worker "worker-001" process 15969 started
2017-09-05T14:52:34+0200 [Router      15969] RouterServiceSession ready [configured on_ready fired]
2017-09-05T14:52:34+0200 [Router      15969] Realm 'realm1' started
2017-09-05T14:52:34+0200 [Controller  15960] Router 'worker-001': realm 'realm-001' (named 'realm1') started
2017-09-05T14:52:34+0200 [Router      15969] role role-001 on realm realm-001 started
2017-09-05T14:52:34+0200 [Controller  15960] Router 'worker-001': role 'role-001' (named 'authenticator') started on realm 'realm-001'
2017-09-05T14:52:34+0200 [Router      15969] role role-002 on realm realm-001 started
2017-09-05T14:52:34+0200 [Controller  15960] Router 'worker-001': role 'role-002' (named 'public') started on realm 'realm-001'
2017-09-05T14:52:34+0200 [Router      15969] started component: labgrid.remote.authenticator.AuthenticatorSession id=1175882440106437
2017-09-05T14:52:34+0200 [Controller  15960] Router 'worker-001': component 'component-001' started
2017-09-05T14:52:34+0200 [Router      15969] Site starting on 20408
2017-09-05T14:52:34+0200 [Controller  15960] Router 'worker-001': transport 'transport-001' started
2017-09-05T14:52:34+0200 [Controller  15960] Could not startup node: Traceback (most recent call last):
File "/home/phoenix/.virtualenvs/labgrid/lib/python3.6/site-packages/twisted/internet/defer.py", line 653, in _runCallbacks
current.result = callback(current.result, *args, **kw)
File "/home/phoenix/.virtualenvs/labgrid/lib/python3.6/site-packages/twisted/internet/defer.py", line 1442, in gotResult
_inlineCallbacks(r, g, deferred)
File "/home/phoenix/.virtualenvs/labgrid/lib/python3.6/site-packages/twisted/internet/defer.py", line 1384, in _inlineCallbacks
result = result.throwExceptionIntoGenerator(g)
File "/home/phoenix/.virtualenvs/labgrid/lib/python3.6/site-packages/twisted/python/failure.py", line 393, in throwExceptionIntoGenerator
return g.throw(self.type, self.value, self.tb)
--- <exception caught here> ---
File "/home/phoenix/.virtualenvs/labgrid/lib/python3.6/site-packages/crossbar/controller/node.py", line 597, in start
yield self._startup()
File "/home/phoenix/.virtualenvs/labgrid/lib/python3.6/site-packages/twisted/internet/defer.py", line 1386, in _inlineCallbacks
result = g.send(result)
File "/home/phoenix/.virtualenvs/labgrid/lib/python3.6/site-packages/crossbar/controller/node.py", line 656, in _configure_node_from_config
assert worker_type in self._native_workers
builtins.AssertionError:

# Fixed code
def stop_component(self, component_id, details=None):
    """
    Stop a component currently running within this container.

    :param component_id: The ID of the component to stop.
    :type component_id: int

    :param details: Caller details.
    :type details: instance of :class:`autobahn.wamp.types.CallDetails`

    :returns: Stop information.
    :rtype: dict
    """
    self.log.debug(
        "{klass}.stop_component({component_id}, {details})",
        klass=self.__class__.__name__,
        component_id=component_id,
        details=details,
    )

    if component_id not in self.components:
        raise ApplicationError(
            "crossbar.error.no_such_object",
            "no component with ID {} running in this container".format(component_id),
        )

    component = self.components[component_id]

    try:
        component.proto.close()
    except:
        self.log.failure(
            "failed to close protocol on component '{component_id}': {log_failure}",
            component_id=component_id,
        )
        raise
    else:
        # essentially just waiting for "on_component_stop"
        yield component._stopped

    stopped = {
        "component_id": component_id,
        "uptime": (datetime.utcnow() - component.started).total_seconds(),
        "caller": {
            "session": details.caller if details else None,
            "authid": details.caller_authid if details else None,
            "authrole": details.caller_authrole if details else None,
        },
    }

    # the component.proto above normally already cleaned it up
    if component_id in self.components:
        del self.components[component_id]

    # FIXME: this is getting autobahn.wamp.exception.TransportLost
    if False:
        self.publish(
            "{}.on_component_stopped".format(self._uri_prefix),
            stopped,
            options=PublishOptions(exclude=details.caller),
        )

    returnValue(stopped)