commaai / openpilot

openpilot is an operating system for robotics. Currently, it upgrades the driver assistance system on 275+ supported cars.
https://comma.ai/openpilot
MIT License
49.94k stars 9.11k forks source link

Changing streams on Cabana crashes on MacOS #34037

Open pbassut opened 2 days ago

pbassut commented 2 days ago

Describe the bug

Whenever you try to open another stream while already having a stream open, looks like the current socket is not closed properly and when trying to bind again it fails.

(openpilot) ~/P/c/openpilot (master|✚2) [SIGABRT]$ ./tools/cabana/cabana 625ccd09daec723c/00000055--3b455c2343/0
Warning: Setting a new default format with a different version or profile after the global shared context is created may cause issues with context sharing.
QCommandLineParser: option not defined: "socketcan"
active services: can, carParams, driverEncodeIdx, roadEncodeIdx, wideRoadEncodeIdx
loading route 625ccd09daec723c/00000055--3b455c2343/0
load route 625ccd09daec723c|00000055--3b455c2343 with 1 valid segments
Starting listener for: camerad
Error, failed to bind PubSocket to can: Address already in use
Assertion failed: (socket), function PubMaster, file socketmaster.cc, line 191.
fish: Job 1, './tools/cabana/cabana 625ccd09d…' terminated by signal SIGABRT (Abort)

Provide a route where the issue occurs

625ccd09daec723c/00000055--3b455c2343/0

openpilot version

0.9.7

Additional info

Here's a gif showing the crash. Kapture 2024-11-16 at 09 41 52

deanlee commented 1 day ago

Cabana relies on class OpenpilotPrefix (common/prefix.h) to set different environments for different streams, allowing multiple instances of Cabana to run simultaneously or switch between streams while running. However, OpenpilotPrefix is currently only supported on Linux, which leads to this issue on MacOs.

Here is the related TODO in Cabana

https://github.com/commaai/openpilot/blob/8c8ac3f28f37d7868259b76ca6cd0a149fdd6944/tools/cabana/streams/replaystream.cc#L16-L23