Skip to content

Conversation

@xieNniu
Copy link

@xieNniu xieNniu commented Jan 16, 2026

Added thread-safe protection for obstacle point cloud data in D435Provider to prevent race conditions when accessing shared state from multiple threads.

Changes:

  • Introduced threading.Lock to protect read/write operations on the obstacle data structure
  • Converted obstacle to private attribute _obstacle with a thread-safe @property getter method
  • Enhanced error logging in obstacle_callback with exc_info=True for better debugging context
  • Added comprehensive NumPy-style docstring to __init__ method documenting initialization flow and thread safety mechanisms
  • Updated class-level docstring to describe thread-safe characteristics and asynchronous callback behavior

Technical Details:

  • The obstacle_callback method runs asynchronously in a separate thread when Zenoh receives point cloud data from the camera/realsense2_camera_node/depth/obstacle_point topic
  • Without thread synchronization, concurrent access to self.obstacle from the callback thread and main thread could lead to race conditions
  • The lock ensures atomic updates when processing point cloud data and calculating obstacle coordinates (x, y, z, angle, distance)

Files Modified:

  • src/providers/d435_provider.py

@xieNniu xieNniu requested review from a team as code owners January 16, 2026 13:38
@github-actions github-actions bot added robotics Robotics code changes python Python code labels Jan 16, 2026
@xieNniu xieNniu force-pushed the fix/d435-thread-safety branch from 32aa78a to 0827bcc Compare January 20, 2026 22:49
Copy link
Collaborator

@Wanbogang Wanbogang left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you please resolve the conflicts?

@xieNniu xieNniu requested review from a team as code owners February 2, 2026 01:08
@github-actions github-actions bot added the documentation Improvements or additions to documentation label Feb 2, 2026
@xieNniu xieNniu force-pushed the fix/d435-thread-safety branch 2 times, most recently from 038998f to f61ea91 Compare February 2, 2026 01:10
@xieNniu xieNniu force-pushed the fix/d435-thread-safety branch from f61ea91 to 058207b Compare February 2, 2026 01:16
@Wanbogang
Copy link
Collaborator

@xieNniu
Thread locking is technically correct, but for this use case it adds complexity without significant benefit. Consider simplifying it.

@codecov
Copy link

codecov bot commented Feb 10, 2026

Codecov Report

❌ Patch coverage is 27.27273% with 8 lines in your changes missing coverage. Please review.
✅ All tests successful. No failed tests found.

Files with missing lines Patch % Lines
src/providers/d435_provider.py 27.27% 8 Missing ⚠️

📢 Thoughts on this report? Let us know!

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

Labels

documentation Improvements or additions to documentation python Python code robotics Robotics code changes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants