Skip to content

Backport TcpServer shutdown-hang fix - #5687

Merged
LeStarch merged 4 commits into
nasa:release/v3.6.0-hotfixesfrom
nathancheek:release/v3.6.0-hotfixes
Aug 17, 2026
Merged

LeStarch merged 4 commits into
nasa:release/v3.6.0-hotfixesfrom
nathancheek:release/v3.6.0-hotfixes

Conversation

@nathancheek

@nathancheek nathancheek commented Aug 14, 2026 •

Copy link
Copy Markdown
Contributor
Related Issue(s) Backports #5202, #5336
Has Unit Tests (y/n) n
Documentation Included (y/n) y
Generative AI was used in this contribution (y/n) y

Change Description

Backports the TcpServer shutdown-hang fix and the IP close() file descriptor guards from devel to release/v3.6.0-hotfixes, plus a change to TcpServer stop() needed to keep the v3.6 teardown API working.

Also removes a delay at shutdown by checking if thread is running before a delay(SOCKET_RETRY_INTERVAL).

Updates documentation of affected functions (note that socket documentation in devel is outdated, I will open a separate PR to tackle that).

Rationale

Currently, v3.6 deployments hang when exiting, if a TcpServer has no active client connection.

Testing/Review Recommendations

Verified against four teardown scenarios:

Scenario Before After
Client never connected join() hangs returns immediately
Client connected, then disconnected join() hangs returns immediately
Client still connected returns returns
Listen port unavailable returns (~1s) returns (~1s)

I tested all 8 iterations of this before/after test on two deployments: an internal project deployment plus a modified fprime-tutorial-hello-world. In order to get fprime-tutorial-hello-world to demonstrate this fix, I made 3 changes to the v3.6.0 deployment:

  • Switched Drv.TcpClient to Drv.TcpServer in instances.fpp
  • Moved comm.stop() and comm.join() above stopTasks() (order matters to keep the deployment from hanging at shutdown, at least in v3.6)
  • Added a Svc.ComQueue in the downlink path (a different unresolved bug causes a thread sending via TcpServer to hang on accept() when no client is connected. Without this ComQueue in the middle, the tlm-generating rategroup sits in accept() until it eventually asserts due to full component queue at TlmChanComponentAc.cpp:483).

Future Work

Claude proposed some unit tests, which I did not include, because they would hang indefinitely if failing, which didn't seem ideal. But it may be possible to write unit tests to demonstrate this behavior, if desired.

AI Usage (see policy)

Claude helped me compare v3.6 socket components to v4 in order to properly backport this change. It provided some initial documentation and commit message examples which I used as inspiration. Finally, it reviewed my work and provided recommendations before I submitted this PR.

nathancheek and others added 3 commits August 13, 2026 18:09
…ards (nasa#5336)

* TcpServer now reliably shuts down instead of reliably hanging on accept()
  - Note: previously, calling TcpServerComponentImpl::terminate() would release
    the listening port, but allow an established connection to continue. Now,
    it drops any active client connections too.
* IP close() calls now guard against invalid file descriptors
* Fixed documentation regarding TcpServerSocket::shutdown which was renamed to
  "terminate" in nasa#2950

Co-authored-by: M Starch <LeStarch@googlemail.com>
Co-authored-by: lestarch-autobot <lestarch+autobot@gmail.com>
Co-authored-by: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
Co-authored-by: michael.d.starch <michael.d.starch@jpl.nasa.gov>
* v4 deployments can exit cleanly with stop() because their read task no longer
  performs accept(). In v3.6, the read task still performs accept(), so stop()
  must also tear down the listening socket to keep that task from blocking on
  accept() indefinitely.

* Note: stop() is now equivalent to terminate() for TcpServer. It releases the
  listening port even when the read task was never started.
* Speeds up topology teardown by removing SOCKET_RETRY_INTERVAL delay
  when terminating socket component (e.g. TcpServer)
@LeStarch
LeStarch merged commit 1b06610 into nasa:release/v3.6.0-hotfixes Aug 17, 2026
36 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