Conversation
Greptile SummaryThis PR refactors transport lifecycle management by implementing previously empty Key changes:
The refactoring maintains backward compatibility as the lazy initialization behavior (starting on first use) remains unchanged. Confidence Score: 4/5
Important Files Changed
Sequence DiagramsequenceDiagram
participant Client
participant Transport as Transport (LCM/SHM)
participant Backend as Backend (lcm/shm)
Note over Client,Backend: Before: Inline start logic
Client->>Transport: broadcast(msg) / subscribe(callback)
Transport->>Transport: Check _started flag
alt not started
Transport->>Backend: lcm.start() / shm.start()
Transport->>Transport: Set _started = True
end
Transport->>Backend: publish(msg) / subscribe(callback)
Note over Client,Backend: After: Centralized start() method
Client->>Transport: broadcast(msg) / subscribe(callback)
Transport->>Transport: Check _started flag
alt not started
Transport->>Transport: start()
Transport->>Backend: lcm.start() / shm.start()
Transport->>Transport: Set _started = True
end
Transport->>Backend: publish(msg) / subscribe(callback)
Note over Client,Backend: Lifecycle management
Client->>Transport: stop()
Transport->>Backend: lcm.stop() / shm.stop()
Transport->>Transport: Set _started = False
|
There was a problem hiding this comment.
Additional Comments (6)
-
dimos/core/transport.py, line 63-66 (link)style:
pLCMTransportwasn't refactored to useself.start()like the other transport classes. Should callself.start()instead for consistency.Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!
-
dimos/core/transport.py, line 73-75 (link)style: Same as in
broadcast()- should useself.start()for consistency.Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!
-
dimos/core/transport.py, line 78 (link)style:
pLCMTransport.start()should implement the method body like other transport classes.Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!
-
dimos/core/transport.py, line 80-81 (link)style:
pLCMTransport.stop()should reset_startedflag like other transport classes. -
dimos/core/transport.py, line 142-146 (link)style:
pSHMTransport.broadcast()wasn't refactored to useself.start()like the other transport classes. Should callself.start()for consistency.Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!
-
dimos/core/transport.py, line 149-152 (link)style: Same as in
broadcast()- should useself.start()for consistency.Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!
1 file reviewed, 6 comments
|
@greptile |
| if not self._started: | ||
| self.lcm.start() | ||
| self._started = True | ||
| self.start() |
There was a problem hiding this comment.
style: check-then-act race condition in concurrent scenarios - if two threads call broadcast() simultaneously when _started is False, both could call start() leading to multiple start calls on the underlying transport
| if not self._started: | |
| self.lcm.start() | |
| self._started = True | |
| self.start() | |
| with getattr(self, '_start_lock', threading.Lock()): | |
| if not self._started: | |
| self.start() |
There was a problem hiding this comment.
Actually greptile is pointing out a legitimate issue here, LCM start() is instant and almost cannot fail (udp cannot fail to connect) so this is why we are so chill, ignoring start() and autostarting in broadcast() to save some resources.
Other protocols are slower, have legitimate slower blocking Start() processes, that can fail with "connection failiure" and such, so we expect them to have fat start() functions (ROS, some TCP connection etc, even SSH)
It makes sense to remove autostart from LCM if we want to be extra nitpicky, that's ok.
but definitely other protocols are not supposed to autostart like this and should have legitimate start() implementations
since we want our broadcast() and subscribe() functions to be instant, we are assuming tge transport is ready at that point, these shouldn't trigger unanticipated slow connection attempts, (especially without locks as greptile mentions, for like camera you'll get actual 30 parallel connection attempts per second - if we run DDS over ssh for agibot, this will be 100reds of SSH connection attemps, or (with a lock) a weird invisible message buffer filling)
leshy
left a comment
There was a problem hiding this comment.
we are autoiniting SHM and LCM which are instant so this is fine, but we won't be doing the same for other protocols
… Unitree Go2 Navigation & Exploration Beta Pre-Release v0.0.8: Unitree Go2 Navigation & Exploration Beta, Transport Updates, Documentation updates, Rerun fixes, Person follow, Readme updates ## What's Changed * Small docs clarification about stream getters by @leshy in #1043 * Fix split view on wide monitors by @jeff-hykin in #1048 * Docs: Install & Develop by @jeff-hykin in #1022 * Add uv to nix and fix resulting problems by @jeff-hykin in #1021 * v0.0.8 by @paul-nechifor in #1050 * Style changes in docs by @paul-nechifor in #1051 * Revert "Add uv to nix and fix resulting problems" by @leshy in #1053 * Transport benchmarks + Raw ros transport by @leshy in #1038 * feat: default to rerun-web and auto-open browser on startup (browser … by @Nabla7 in #1019 * bbox detections visual check by @leshy in #1017 * fix: only auto-open browser for rerun-web viewer backend by @Nabla7 in #1066 * move slow tests to integration by @paul-nechifor in #1063 * Streamline transport start/stop methods by @Kaweees in #1062 * Person follow skill with EdgeTAM by @paul-nechifor in #1042 * fix: increase costmap floor z_offset to avoid z-fighting by @Nabla7 in #1073 * Fixed issue #1074 by @alexlin2 in #1075 * ROS transports initial by @leshy in #1057 * Fix System Config Values for LCM on MacOS and Refactor by @jeff-hykin in #1065 * SHM Transport basic fixes by @leshy in #1041 * commented out Mem Transport test case by @leshy in #1077 * Docs/advanced streams update 2 by @leshy in #1078 * Fix more tests by @paul-nechifor in #1071 * feat: navigation docker updates from bona_local_dev by @baishibona in #1081 * Fix missing dependencies by @Kaweees in #1085 * Release readme fixes by @spomichter in #1076 ## New Contributors * @baishibona made their first contribution in #1081 **Full Changelog**: v0.0.7...v0.0.8
Several transport classes (LCMTransport, JpegLcmTransport, pSHMTransport, SHMTransport, JpegShmTransport) had empty start() and stop() method stubs (...). These are now fully implemented to properly start/stop the underlying transport and manage the _started flag.