Repository navigation
Stop socket subscription listener thread on destruction - #77
Merged
Merged
Conversation
The POSIX socket subscription transport's listener thread looped forever and was never joined, so destroying the transport called std::terminate. The listener now polls with a timeout and checks a run flag, and the destructor clears the flag and joins the thread before the socket is closed. Failed reads are skipped instead of being passed to the decoder as a huge length. ThingSetListener::subscribe also captured its callback parameter by reference in the lambda it hands to the transport, leaving a dangling reference once subscribe() returned. It now captures by copy. Adds end-to-end publish/subscribe tests for the socket transports. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
amitchone
approved these changes
Nov 6, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
ThingSetSocketSubscriptionTransport(POSIX) starts a listener thread that loops forever in a blockingrecvfrom()and is never joined or detached. Destroying the transport destroys a joinablestd::thread, which callsstd::terminate. This is also why there were no socket publish/subscribe tests.Changes
poll()(10 ms timeout) and checks a_runListenerflag. The POSIX transport has a new destructor that clears the flag and joins the thread before the base class closes the socket. This follows the same pattern asThingSetSocketServerTransportandRawCanSocketListener. No change to the base subscription interface.recvfrom()error is now skipped. Previously -1 was stored inFrame::length(asize_t) and passed to the decoder as a huge length.ThingSetListener::subscribe: the lambda passed to the transport captured[&], including thecallbackparameter, which no longer exists oncesubscribe()returns. Every report then called through a dangling reference (the Asio publish/subscribe test only passed by luck). It now capturescallbackby copy. This header is shared by all transports.Tests
New
TestSocketIpPublishSubscribe.cpp(non-Apple only, like the other socket tests):All four passed 30 out of 30 repeated runs in the
gcccontainer. Against the original transport code, the first one aborts the test binary withterminate called without an active exception.Two existing failures on
mainare not touched here:ServesClientInReusedSlotWhileOthersIdlefails intermittently (fixed in the socket client/server tests PR), andTextDecoder.DecodeStringfails in the full suite.Note:
ThingSetListener.hppdoesn't include the headers it uses (ThingSetRegistry,ThingSetNodeType), so the new test includesThingSetServer.hppfirst, as the Asio test does.🤖 Generated with Claude Code