Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

./cabana --panda and ./cabana --panda-serial <panda-serial> segfault, Cabana shows panda's serial while also saying "No panda found" #32479

Closed
librick opened this issue May 19, 2024 · 3 comments · Fixed by #32537
Labels

Comments

@librick
Copy link

librick commented May 19, 2024

Describe the bug

I compiled openpilot on Debian. I'm trying to get Cabana to use my Red Panda.

When I run ./cabana --panda on my laptop, I get a segfault every time, regardless of whether the panda is connected. GDB shows:

Thread 11 "QThread" received signal SIGSEGV, Segmentation fault.
[Switching to Thread 0x7fffc9c006c0 (LWP 73412)]
Panda::connected (this=0x0) at selfdrive/boardd/panda.cc:34
34	 return handle->connected;
(gdb) 

I found that the void PandaStream::streamThread() {...} method in openpilot/tools/cabana/streams/pandastream.cc attempts to call the bool Panda::connected() {...} method in openpilot/selfdrive/boardd/panda.cc, which attempts to reference handle->connected when handle is a nullptr.

if (!panda->connected()) {
      qDebug() << "Connection to panda lost. Attempting reconnect.";
      if (!connect()){
        QThread::msleep(1000);
        continue;
      }
    }
bool Panda::connected() {
  return handle->connected;
}

./cabana --panda-serial <panda-serial> segfaults in the same place.

This is part of a larger issue where I'm not seeing any CAN messages from the panda (connected to a 2021 Honda Civic Hatchback with the Honda Bosch A wire harness).

I can connect to my panda using the panda python library (https://github.com/commaai/panda) and get the panda's serial number and firmware version, but when I try to log CAN messages (with my car engine running) I never see them.

I can connect to my panda when I start Cabana with ./cabana (it appears in the dropdown), but Cabana doesn't show any CAN messages (with my car engine running). Weirder still, if I start Cabana and choose my panda at the start screen, then go to File > Open Stream..., the dialog that comes up shows my panda's serial number selected and says "No panda found".

Here's a screenshot. I redacted my panda's serial number in case it's sensitive info somehow, if you need it to debug just let me know. The firmware version is DEV-b4442a7c-RELEASE

image

Thanks for any help!

Provide a route where the issue occurs

N/A

openpilot version

5cfaae7

Additional info

No response

@librick librick added the bug label May 19, 2024
@librick librick changed the title ./cabana --panda and ./cabana --panda-serial <panda-serial> segfault, Cabana shows panda serial and "No panda found" ./cabana --panda and ./cabana --panda-serial <panda-serial> segfault, Cabana shows panda's serial while also saying "No panda found" May 19, 2024
@librick
Copy link
Author

librick commented May 21, 2024

I looked into this more. I think the relevant files (not including headers) are:

  • cabana.cc
  • abstractstream.cc
  • livestream.cc
  • pandastream.cc

In cabana.cc, the following code initializes a new PandaStream:

else if (cmd_parser.isSet("panda") || cmd_parser.isSet("panda-serial")) {
    PandaStreamConfig config = {};
    if (cmd_parser.isSet("panda-serial")) {
      config.serial = cmd_parser.value("panda-serial");
    }
    try {
      stream = new PandaStream(&app, config);
    } catch (std::exception &e) {
      qWarning() << e.what();
      return 0;
    }
  }

And later calls stream->start();

PandaStream derives from LiveStream derives from AbstractStream.

  • cabana.cc constructs a PandaStream which derives from LiveStream
  • The constructor of LiveStream creates a stream_thread
  • The constructor of LiveStream wires the &QThread::started signal to streamThread():
  • cabana.cc calls stream->start();
  • which invokes void LiveStream::start()
  • which calls stream_thread->start();
  • which causes stream_thread to emit a &QThread::started
  • which causes void PandaStream::streamThread(); to be invoked

void PandaStream::streamThread() has the following code:

if (!panda->connected()) {
      qDebug() << "Connection to panda lost. Attempting reconnect.";
      if (!connect()){
        QThread::msleep(1000);
        continue;
      }
    }

panda->connected() segfaults because panda is a nullptr.

pandastream.h declares panda as std::unique_ptr<Panda> panda;.
I think the pointer is only ever assigned from bool PandaStream::connect(), which I think is only ever called from bool OpenPandaWidget::open().

Am I missing something, is a segfault expected for some reason in this case?

@librick
Copy link
Author

librick commented May 21, 2024

This segfault only happens via the CLI (not when the UI launches), because:

  • when no options are passed to cabana.cc, void MainWindow::openStream() is called
  • which inits a new stream selector dialog StreamSelector dlg(&stream, this);
  • which calls AbstractOpenStreamWidget *PandaStream::widget(AbstractStream **stream)
  • which inits OpenPandaWidget
  • the user selects the panda, invoking bool OpenPandaWidget::open()
  • which calls panda_stream->connect()
  • which calls panda.reset(new Panda(config.serial.toStdString()));

And I think this all happens before void PandaStream::streamThread() is invoked, because stream->start(); isn't invoked until after a stream is selected.

@librick
Copy link
Author

librick commented May 24, 2024

I think my underlying issue might be that I'm trying to execute ./cabana directly without boardd

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant