Fix automatic reconnect#108
Conversation
After Disconnect(), params_.stream_ was cleared, but the worker thread's reconnect path calls Connect() which re-reads params_.stream_ to decide between TCP and serial. With an empty string both prefix checks fail and the driver logs "Bad stream spec:" and gives up — permanently, since the config is gone. The only recovery is a process restart. Reproduction: trigger a sensor SYSTEM_REBOOT via the HTTP API. The TCP read returns ECONNRESET, the worker calls Disconnect() (which clears the stream), then loops calling Connect() every reconnect_delay_ seconds — all of which now fail with an empty stream spec. Fix: don't clear params_.stream_ on disconnect. The field is the connection config, not connection state — it should persist for the lifetime of the driver instance.
|
|
@flipflip8952 Thanks for the comment, I've updated the description and title accordingly. 👍 |
|
@SijmenHuizenga original description. Moved here so that it doesn't end up in the commit description.
sensor_fd_ = -1;
params_.stream_.clear();The worker loop ( else {
INFO("Reconnecting in %.1f seconds...", params_.reconnect_delay_);
if (worker_.Sleep(params_.reconnect_delay_ * 1000) == WaitRes::WOKEN) {
break;
}
Connect();
}But if (string::StrStartsWith(params_.stream_, "tcpcli://")) { ... }
else if (string::StrStartsWith(params_.stream_, "serial://")) { ... }
WARNING("Bad stream spec: %s", params_.stream_.c_str());
return false;With How to reproduce Trigger any event that causes |
Re-connect is broken because the stream spec is cleared on disconnect. By removing the 'clear' statement, subsequent reconnect attempts will work.