Skip to content

fix: ensure all spawned actors are destroyed on shutdown (closes #698) - #764

Open
redddddyyyyy wants to merge 2 commits into
carla-simulator:masterfrom
redddddyyyyy:fix/698-incomplete-actor-cleanup
Open

fix: ensure all spawned actors are destroyed on shutdown (closes #698)#764
redddddyyyyy wants to merge 2 commits into
carla-simulator:masterfrom
redddddyyyyy:fix/698-incomplete-actor-cleanup

Conversation

@redddddyyyyy

@redddddyyyyy redddddyyyyy commented Apr 16, 2026

Copy link
Copy Markdown

Problem

Fixes #698

When pressing Ctrl+C, the ROS node exits but spawned CARLA actors (vehicles, sensors) remain alive in the simulator. The root cause is that the destroy loops in carla_spawn_objects.py wrap all actors in a single try-except — any one exception exits the entire loop, leaving remaining actors alive. The same pattern exists in bridge.py and actor_factory.py with no exception handling at all.

Fix

Wrap each individual actor destruction call in its own try-except block across three files:

  • carla_spawn_objects/src/carla_spawn_objects/carla_spawn_objects.py: per-actor try-except in destroy()
  • carla_ros_bridge/src/carla_ros_bridge/bridge.py: per-actor try-except in destroy()
  • carla_ros_bridge/src/carla_ros_bridge/actor_factory.py: per-actor try-except in clear()

Failed destructions are logged as warnings but do not abort cleanup of remaining actors. Lists are copied before iteration to prevent mutation issues during teardown.

Testing

The fix has been verified by code review. The change is mechanical — moving exception handling from wrapping entire loops to wrapping individual iterations — and the logic is straightforward to confirm by reading.


This change is Reviewable

…lator#698)

Wrap each actor destruction call in its own try-except block so a
single failure does not abort cleanup of remaining actors. Failures
are logged as warnings. Lists are copied before iteration to prevent
mutation issues during teardown.
@redddddyyyyy

Copy link
Copy Markdown
Author
  • Traced shutdown cleanup to the deferred destroy-task consumer: destroy_actor() enqueues work, while ActorFactory.update_available_objects() executes _destroy_object().
  • Added per-task exception handling at that execution boundary so one failed actor destruction is logged and later queued actors are still attempted.
  • Added test_actor_factory_cleanup.py to reproduce the original abort and verify queue continuation, plus ROS 1 catkin_add_nosetests registration.
  • Local focused verification: 1 test passed; the touched Python files compiled; the staged diff passed git diff --check.
  • ROS/CARLA integration was not run locally because the current Windows machine does not have ROS or CARLA installed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Shutting down node using Ctrl+C, doesnt completely destroy all the spawned objects

1 participant