Skip to content

fix: ANT server stops forwarding messages after 65535 messages - #191

Draft
gdoumen wants to merge 10 commits into
masterfrom
fix/ant-stick-stall
Draft

gdoumen wants to merge 10 commits into
masterfrom
fix/ant-stick-stall

Conversation

@gdoumen

@gdoumen gdoumen commented Nov 24, 2026

Copy link
Copy Markdown
Contributor

Summary

On Windows the ANT+ server (AntServer.bin) stops forwarding ANT messages after 65535 messages, which is about an hour of riding with four sensors. The USB stick keeps receiving and the server keeps answering requests (including the heartbeat echo), so the app cannot tell, loses all sensors and only recovers after the app is restarted.

Cause

The framer queued every received message and only printed it to stdout while the queue had room. Nothing in the server ever reads that queue, so it was full after 65535 messages and from then on nothing was printed.

What changed

  • Forward each message right away and do not queue it.
  • Write every stdout line in one piece under a lock. The thread that reads requests and the thread that receives from the stick wrote at the same time, which could mix up two lines and produce truncated messages (Illegal message on the host side).
  • New workflow that builds antserver.exe with the same SDK sources and the MSVC v140 toolset, fails if the binary needs a newer runtime than the one the desktop app ships, smoke-tests the heartbeat echo and uploads ANTserver.bin as an artifact.

Test plan

  • Workflow builds and the smoke test passes
  • Dependencies listed in the workflow artifact are limited to the VS2015 runtime
  • Ride more than 65 minutes with four ANT+ sensors (or a simulator) using the built ANTserver.bin: data keeps flowing
  • Output helper checked locally with g++ and a two-thread stress test (old style: about 29% corrupted lines, new helper: none)

The framer only printed a received message to stdout while the internal message
queue had room, and queued every message. Nothing in the server ever reads that
queue, so it was full after 65535 messages (about an hour with four sensors).
From then on no message reached the host any more, while the USB stick kept
receiving and the server kept answering requests, so the host could not tell
that the stick was no longer being served.

Forward each message right away and do not queue it.

Also write every stdout line in one piece under a lock. The thread that reads
requests and the thread that receives from the stick wrote to stdout at the
same time, which could mix up two lines and make the host reject a truncated
message.

The server has to be rebuilt with Visual Studio (toolset v140) to take effect. Not compiled in this change; the output helper was checked with g++ -std=c++11 including a two-thread stress test.
Builds antserver/ with the same SDK sources and the MSVC v140 toolset, fails if the binary depends on a newer runtime than the one the desktop app ships, smoke-tests the ping echo and uploads ANTserver.bin as an artifact.
Comment thread .github/workflows/antserver.yml Fixed
bBursting was never initialized. Members are now set in the initializer list. The server object in main is deliberately kept alive until the process ends; marked so that the analysis does not report it as a leak.
Built by the antserver workflow (run 45451739207) from 6b02fb6, MSVC v140, SHA-256 7d7452f37c0358ebc09694f1c8721f03c4f2b34a81f971f051c96260d8910777.
…gain

The framer and serial objects were created with new on every open and never freed, about 3 MB per open. They are now owned by unique_ptr and released (receive thread of the stick first) before the next open and on destruction. Members are initialized where they are declared.

The smoke test now also opens and closes the device twice and checks that the server still answers.
Built by the antserver workflow (run 45458021987) from 6a05f12, MSVC v140, SHA-256 c4a50f7f77ff4cad1c42a1ff1ae3b4595fae4dff466216aacf17a93286044c36.
@sonarqubecloud

Copy link
Copy Markdown

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