Skip to content

ENT-14927: Fixed cf-serverd crash when policy reload races with a new connection - #6464

Merged
olehermanse merged 1 commit into
cfengine:masterfrom
aleksandrychev:ENT-14927
Nov 10, 2026
Merged

olehermanse merged 1 commit into
cfengine:masterfrom
aleksandrychev:ENT-14927

Conversation

@aleksandrychev

Copy link
Copy Markdown
Contributor

Ticket: ENT-14927

cf-serverd decides it is safe to reload policy (and to free ACLs/TLS on shutdown) by checking ACTIVE_THREADS == 0. But a connection is added to SERVER_ACCESS.connectionlist in ServerEntryPoint() before its handler thread increments ACTIVE_THREADS, and removed in DeleteConn() only after the thread has decremented it. A reload in either window hits assert(SERVER_ACCESS.connectionlist == NULL) in ClearAuthAndACLs().

Seen in CI as a hub crash during bootstrap-tests (bootstrap-tests #1130):

cf-serverd-functions.c:381: ClearAuthAndACLs: Assertion `SERVER_ACCESS.connectionlist == NULL' failed.
  main thread:  ClearAuthAndACLs <- CheckFileChanges <- main
  other thread: HandleConnection -> ThreadLock (waiting)

Change: a new ConnectionsInFlight() returns MAX(ACTIVE_THREADS, ListLen(connectionlist)), reading the list under cft_count. PolicyUpdateIfSafe() and WaitOnThreads() use it instead of ACTIVE_THREADS alone. The lock order is cft_server_children then cft_count, which the reload path already does; nothing takes them in the reverse order.

Testing (Debian 12, --enable-debug): cf-serverd with allowallconnects for localhost, 16 threads opening/closing connections to 5308, and SIGHUP every 50 ms for 60 s:

  • before: aborted with the assertion above in 3/3 runs, on the first connection
  • after: 3/3 runs survived (8.4k–28.9k connections and 451–865 reloads per run), clean exit on SIGTERM

The same code is in 3.24.x and 3.27.x, so this should be backported.

🤖 Generated with Claude Code

cf-serverd only checked ACTIVE_THREADS before reloading policy, but a
connection is added to SERVER_ACCESS.connectionlist before its handler
thread increments ACTIVE_THREADS and removed only after it decrements it.
A reload in that window tripped the assertion in ClearAuthAndACLs().
Policy reload and shutdown cleanup now also wait for connections that
are still in connectionlist.

Ticket: ENT-14927
Changelog: Title
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Ihor Aleksandrychiev <ihor.aleksandrychiev@northern.tech>
@aleksandrychev

Copy link
Copy Markdown
Contributor Author

@cf-bottom jenkins please

@cf-bottom

Copy link
Copy Markdown

@aleksandrychev aleksandrychev added the cherry-pick? Fixes which may need to be cherry-picked to LTS branches label Nov 4, 2026

@larsewi larsewi left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM 🚀

@olehermanse
olehermanse merged commit 9b98229 into cfengine:master Nov 10, 2026
46 checks passed
@github-actions

Copy link
Copy Markdown
Contributor

Backport to 3.24.x: #6492

@github-actions

Copy link
Copy Markdown
Contributor

Backport to 3.27.x: #6493

@github-actions github-actions Bot removed the cherry-pick? Fixes which may need to be cherry-picked to LTS branches label Nov 10, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

5 participants