{"record":{"id":"e866825ec6e8bfe7","repo":"commaai/openpilot","slug":"connection-to-panda-lost-attempting-reconnect","errorCode":null,"errorMessage":"Connection to panda lost. Attempting reconnect.\n","messagePattern":"Connection to panda lost\\. Attempting reconnect\\.\n","errorType":"console","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"openpilot/tools/cabana/streams/pandastream.cc","lineNumber":53,"sourceCode":"      if (config.bus_config[bus].can_fd) {\n        panda->set_data_speed_kbps(bus, config.bus_config[bus].data_speed_kbps);\n      } else {\n        // Hack to disable can-fd by setting data speed to a low value\n        panda->set_data_speed_kbps(bus, 10);\n      }\n    }\n  }\n  return true;\n}\n\nvoid PandaStream::streamThread() {\n  std::vector<can_frame> raw_can_data;\n\n  while (!exit_) {\n    std::this_thread::sleep_for(std::chrono::milliseconds(1));\n\n    if (!panda->connected()) {\n      fprintf(stderr, \"Connection to panda lost. Attempting reconnect.\\n\");\n      if (!connect()){\n        std::this_thread::sleep_for(std::chrono::milliseconds(1000));\n        continue;\n      }\n    }\n\n    raw_can_data.clear();\n    if (!panda->can_receive(raw_can_data)) {\n      fprintf(stderr, \"failed to receive\\n\");\n      continue;\n    }\n\n    MessageBuilder msg;\n    auto evt = msg.initEvent();\n    auto canData = evt.initCan(raw_can_data.size());\n    for (uint i = 0; i<raw_can_data.size(); i++) {\n      canData[i].setAddress(raw_can_data[i].address);\n      canData[i].setDat(kj::arrayPtr((uint8_t*)raw_can_data[i].dat.data(), raw_can_data[i].dat.size()));","sourceCodeStart":35,"sourceCodeEnd":71,"githubUrl":"https://github.com/commaai/openpilot/blob/516ec1e68203439a73f340f1d0b3b91eabc626ee/openpilot/tools/cabana/streams/pandastream.cc#L35-L71","documentation":"Emitted by the PandaStream receive thread (tools/cabana/streams/pandastream.cc) when panda->connected() returns false mid-stream: the USB link to the panda device dropped after a previously successful connect(). The thread logs once per failed poll, tries connect() again, and on failure sleeps 1 s and retries — this is a reconnect notice, not a fatal error.","triggerScenarios":"Running a live panda stream in cabana and the device disappears: USB cable unplugged, panda rebooted (e.g. after a firmware flash), USB hub power management suspending the device, or the panda entering a bad state. Each loop iteration (~1 ms cadence) with !panda->connected() prints the message; successful reconnect stops it, so a flapping link prints it repeatedly.","commonSituations":"Loose/damaged USB cable or port during a drive replay or bench testing; panda flashing/firmware update mid-session; udev power-management autosuspend on Linux grabbing the interface; VM passthrough dropping the USB device.","solutions":["Check and reseat the USB cable/connection to the panda (physical layer first — most common cause).","Disable USB autosuspend for the panda: check /sys/bus/usb/devices/*/power/control is 'on', or add a udev rule.","If a flash/reboot was intentional, just wait — the thread auto-reconnects within ~1 s of the device returning.","Re-run with `lsusb`/dmesg to confirm the device enumerates; if not, the reconnect loop cannot succeed until it does."],"exampleFix":"# before: message repeats, device gone from bus\nlsusb | grep -i comma   # nothing\ndmesg | tail   # 'device disconnected'\n\n# after: reseat cable / disable autosuspend\necho -1 > /sys/module/usbcore/parameters/autosuspend\nlsusb | grep -i comma   # device back; stream reconnects on its own","handlingStrategy":"retry","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":["Use a quality short USB cable and a powered hub for bench panda work; most drops are physical.","Disable USB autosuspend for the panda (udev rule or /sys power/control=on).","Don't unplug/replug mid-stream and expect zero messages — the thread auto-reconnects within ~1 s; treat this line as informational noise unless it repeats."],"tags":["panda","usb","reconnect","can-stream","hardware"],"backgroundTag":null,"analyzedSha":"516ec1e68203439a73f340f1d0b3b91eabc626ee","analyzedAt":"2026-08-15T00:17:37.461Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}