Skip to content

Fix automatic reconnect#108

Merged
flipflip8952 merged 1 commit into
fixposition:mainfrom
SijmenHuizenga:fix/preserve-stream-spec-on-disconnect
May 13, 2026
Merged

Fix automatic reconnect#108
flipflip8952 merged 1 commit into
fixposition:mainfrom
SijmenHuizenga:fix/preserve-stream-spec-on-disconnect

Conversation

@SijmenHuizenga
Copy link
Copy Markdown
Contributor

@SijmenHuizenga SijmenHuizenga commented May 13, 2026

Re-connect is broken because the stream spec is cleared on disconnect. By removing the 'clear' statement, subsequent reconnect attempts will work.

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.
@SijmenHuizenga SijmenHuizenga marked this pull request as ready for review May 13, 2026 08:32
@flipflip8952
Copy link
Copy Markdown
Contributor

  • Change title to something that describes the fix, not the problem. Somethig like "Fix automatic reconnect" perhaps?
  • Please replace the PR description with something much more concise. Something like "Don't clear stream spec string on disconnect, so that subsequent (re)connect attempts will work" perhaps?
    (You can keep the huge text (AI generated?) elsewhere, e.g. in a comment to the PR.)

@SijmenHuizenga SijmenHuizenga changed the title Preserve stream spec on Disconnect so reconnects can succeed Fix automatic reconnect May 13, 2026
@SijmenHuizenga
Copy link
Copy Markdown
Contributor Author

SijmenHuizenga commented May 13, 2026

@flipflip8952 Thanks for the comment, I've updated the description and title accordingly. 👍

@flipflip8952 flipflip8952 self-requested a review May 13, 2026 11:40
Copy link
Copy Markdown
Contributor

@flipflip8952 flipflip8952 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cheers!

@flipflip8952
Copy link
Copy Markdown
Contributor

flipflip8952 commented May 13, 2026

@SijmenHuizenga original description. Moved here so that it doesn't end up in the commit description.


FixpositionDriver::Disconnect() clears params_.stream_ after closing the socket, which makes the worker thread's automatic reconnect path permanently fail.

Disconnect() ends with:

sensor_fd_ = -1;
params_.stream_.clear();

The worker loop (fixposition_driver.cpp Worker()) then loops:

else {
    INFO("Reconnecting in %.1f seconds...", params_.reconnect_delay_);
    if (worker_.Sleep(params_.reconnect_delay_ * 1000) == WaitRes::WOKEN) {
        break;
    }
    Connect();
}

But Connect() decides between TCP and serial purely by inspecting params_.stream_:

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 params_.stream_ empty, both prefix checks fail, the driver logs Bad stream spec: (with empty value) and returns false. The loop repeats forever, no way out short of restarting the process.

How to reproduce

Trigger any event that causes Read() to fail and call Disconnect(). Just reboot the fixposition device. The next recv() returns ECONNRESET, the worker calls Disconnect(), and from that point on the log fills with:

[WARN] read/recv fail: Connection reset by peer (104, ECONNRESET)
[INFO] Disconnecting from tcpcli://10.42.0.109:21000
[INFO] Reconnecting in 5.0 seconds...
[WARN] Bad stream spec:
[INFO] Reconnecting in 5.0 seconds...
[WARN] Bad stream spec:
... forever

@flipflip8952 flipflip8952 merged commit a803fa2 into fixposition:main May 13, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants