Skip to content

ThreadPoolExecutor resource leak on exception #221

@manaspros

Description

@manaspros

File: concordia/agents/entity_agent.py — Lines 267–269
Severity: Medium-High

Description:
A ThreadPoolExecutor is created without using Python's context manager (with statement). If self._parallel_call_() on line 268 raises an exception, executor.shutdown() on line 269 will never execute, leaving threads running in the background. Over time (especially in long-running simulations), this leaks system resources and can lead to thread starvation.

Current code:

executor = futures.ThreadPoolExecutor()
contexts = self._parallel_call_('pre_act', action_spec, executor=executor)
executor.shutdown(wait=True)  # skipped if line above throws

Suggested fix: Use the context manager pattern: with futures.ThreadPoolExecutor() as executor:.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions