Skip to content

fix: filter component fetch to nodes only and safe channel close - #131

Open
synackd wants to merge 1 commit into
mainfrom
pr/c-component-fetch-filter
Open

fix: filter component fetch to nodes only and safe channel close#131
synackd wants to merge 1 commit into
mainfrom
pr/c-component-fetch-filter

Conversation

@synackd

@synackd synackd commented Aug 31, 2026

Copy link
Copy Markdown
Contributor

Description

The original implementation of ComponentInformation fetched the full component list without filtering, causing cache‑misses for non‑Node components and unnecessary processing. Update the SMD client to request only Node components by appending ?type=Node to the endpoint (/hsm/v2/State/Components). The change ensures that ComponentInformation and related cache logic operate correctly for node resources. Additionally, StopCacheRefresh now safely closes its stop channel using a select‑based guard (safeClose) to avoid panics if the channel is closed multiple times. Corresponding tests have been updated to reflect the new behavior. These improvements enhance performance and stability of the SMD client.

Fixes #128 (comment)
Fixes #128 (comment)

Checklist

  • My code follows the style guidelines of this project
  • I have added/updated comments where needed
  • I have added tests that prove my fix is effective or my feature works
  • I have run make test (or equivalent) locally and all tests pass
  • I have updated the relevant documentation (CLI examples, man pages, README, other docs, etc.)
  • DCO Sign-off: All commits are signed off (git commit -s) with my real name and email
  • REUSE Compliance:
    • Each new/modified source file has SPDX copyright and license headers
    • Any non-commentable files include a <filename>.license sidecar
    • All referenced licenses are present in the LICENSES/ directory

Type of Change

  • Bug fix
  • New feature
  • Breaking change
  • Documentation update
  • Dependency update
  • Build system/CI

@synackd
synackd force-pushed the pr/c-component-fetch-filter branch 2 times, most recently from cf0f42f to 86dda3d Compare August 31, 2026 16:28
The original implementation of ComponentInformation fetched the full
component list without filtering, causing cache‑misses for non‑Node
components and unnecessary processing. Update the SMD client to request
only Node components by appending ?type=Node to the endpoint
(/hsm/v2/State/Components). The change ensures that ComponentInformation
and related cache logic operate correctly for node resources.
Additionally, StopCacheRefresh now safely closes its stop channel using
a select‑based guard (safeClose) to avoid panics if the channel is
closed multiple times. Corresponding tests have been updated to reflect
the new behavior. These improvements enhance performance and stability
of the SMD client.

Signed-off-by: Devon Bautista <17506592+synackd@users.noreply.github.com>
@synackd
synackd force-pushed the pr/c-component-fetch-filter branch from 86dda3d to 8db0a0f Compare August 31, 2026 16:32
@synackd
synackd marked this pull request as ready for review August 31, 2026 16:43

@alexlovelltroy alexlovelltroy left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Looks like TestPopulateNodes is failing on this PR. We need to fix that before merging.

Comment on lines +161 to 170
// Ensure the stop channel is closed exactly once.
s.stopOnce.Do(func() {
close(s.stopCacheRefresh)
// safeClose closes the channel only if it hasn't been closed already.
select {
case <-s.stopCacheRefresh:
// already closed
default:
close(s.stopCacheRefresh)
}
})

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Why did we need to expand this?

I think the original has equivalent safety.

@synackd synackd Aug 31, 2026

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Probably not necessary, the main change is to deduplicate the close(). I can revert this block and get rid of the extra close() below. I presume that the close() below is extra?

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