Skip to content

ENT-3868: Improve persistent class logging#6159

Closed
nickanderson wants to merge 2 commits into
cfengine:masterfrom
nickanderson:ENT-3868/improve-persistent-class-logging
Closed

ENT-3868: Improve persistent class logging#6159
nickanderson wants to merge 2 commits into
cfengine:masterfrom
nickanderson:ENT-3868/improve-persistent-class-logging

Conversation

@nickanderson
Copy link
Copy Markdown
Member

@nickanderson nickanderson commented Jun 4, 2026

Summary

  • Fix pre-existing memory leak of existing_info in EvalContextHeapPersistentSave (missing free() on the fall-through and early-return paths)
  • Replace the generic "Updating persistent class '%s'" log message with context-aware messages that distinguish between:
    • Creating a new persistent class (no prior record in the DB)
    • Resetting a timer (existing record with RESET policy)
    • Updating an existing record (expired PRESERVE or changed tags)

This helps diagnose timer_policy behavior from verbose logs, which was the remaining gap identified in ENT-3868.

Before

Updating persistent class 'my_class'

After

Creating persistent class 'my_class' (10 minutes, policy reset)
Resetting persistent class 'my_class' timer to 10 minutes (was 7 minutes remaining)
Persistent class 'my_class' is already in a preserved state -- 7 minutes to go
Updating persistent class 'my_class' (10 minutes, policy preserve)

Changelog

Commit 1: Fix memory leak

existing_info was allocated via xcalloc but never freed on the fall-through path (after the PRESERVE early-return check) or on the error early-return path. Added free(existing_info) in all code paths.

Commit 2: Improve logging

Moved logging into the branches where the existing/new state is already known, replacing the single generic message with descriptive alternatives.

Test plan

  • Verify build succeeds
  • Write a policy with persistence => "10" on a classes promise, run cf-agent -Kv twice — first run should log "Creating", second should log "Resetting"
  • Write a policy using timer_policy => "absolute" in a classes body on a files promise, run twice — should log "Creating" then "already in a preserved state"

Ticket

ENT-3868

existing_info was allocated via xcalloc but never freed on the
early-return (preserve) path, the early-return (read error) path,
or the normal fall-through path.

Signed-off-by: Nick Anderson <nick.anderson@northern.tech>
Replace the generic "Updating persistent class" verbose message with
context-aware messages that distinguish between:

- Creating a new persistent class (no prior DB record)
- Resetting a timer (existing record, policy=reset)
- Updating a preserved class (tags changed or class expired)

This makes it easier to diagnose persistent class timer behavior from
verbose logs without needing to add custom debugging builds.

Ticket: ENT-3868
Changelog: Title
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.

1 participant