Skip to content

fix(dm_driver): join control thread before closing CAN bus on shutdown - #86

Open
jbohg wants to merge 1 commit into
i2rt-robotics:mainfrom
jbohg:fix/dm-driver-shutdown-race
Open

fix(dm_driver): join control thread before closing CAN bus on shutdown#86
jbohg wants to merge 1 commit into
i2rt-robotics:mainfrom
jbohg:fix/dm-driver-shutdown-race

Conversation

@jbohg

@jbohg jbohg commented Aug 17, 2026

Copy link
Copy Markdown

Problem

close() sets self.running = False then immediately calls motor_interface.close() / bus.shutdown() without waiting for the control loop thread to exit. The thread is still mid-iteration when the socket is torn down, causing:
ValueError: file descriptor cannot be a negative integer (-1)

Fix

  • Save the thread as self._control_thread in start_thread()
  • In close(), join the thread (up to 2 s) before calling motor_interface.close()

Save the control loop thread as self._control_thread and join it (up to
2 s) in close() before calling motor_interface.close(). Without this,
bus.shutdown() races the still-running control loop, causing a
'file descriptor cannot be a negative integer (-1)' error on exit.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
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.

1 participant