Skip to content

ROX-36973: Prevent delegated scan hang when no Scanner V2 - #22836

Draft
dcaravel wants to merge 3 commits into
masterfrom
dc/dele-scan-no-hang
Draft

dcaravel wants to merge 3 commits into
masterfrom
dc/dele-scan-no-hang

Conversation

@dcaravel

@dcaravel dcaravel commented Sep 14, 2026

Copy link
Copy Markdown
Collaborator

Description

Delegated scan requests will hang for the full timeout (10 mins) when a Secured Cluster only has Scanner V4 installed and Central does not have Scanner V4 installed.

There is historically no Scanner V2 specific capability/message exchanged between Central/Sensor to indicate Scanner V2 is installed.

Now that Scanner V2 is removed, there is no need for Sensor to try to connect to it. This PR removes that path.

Additionally fixes a potential TOCTOU nil pointer panic in Sensor delegated scanning flow that could occur in an (assumingly) extreme edge case (Central's advertised scanner state changes after a delegated scan starts but before the scan request is sent to scanner)

User-facing documentation

Testing and quality

  • the change is production ready: the change is GA, or otherwise the functionality is gated by a feature flag
  • CI results are inspected

Automated testing

  • added unit tests

How I validated my change

CI and manual testing

A perhaps extreme edge case existed where the singleton
would return a non-nil client at the scan entrypoint point and
then return a nil client later on - causing a nil pointer exception
and crash Sensor.
@openshift-ci

openshift-ci Bot commented Sep 14, 2026

Copy link
Copy Markdown

Skipping CI for Draft Pull Request.
If you want CI signal for your change, please convert it to an actual PR.
You can still manually trigger a test run with /test all

@coderabbitai

coderabbitai Bot commented Sep 14, 2026

Copy link
Copy Markdown
Contributor

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Central YAML (base), Organization UI (inherited)

Review profile: CHILL

Plan: Advanced

Run ID: 7a754766-d461-4255-945e-7d38d3f823b1

📥 Commits

Reviewing files that changed from the base of the PR and between 5521eb0 and d46f942.

📒 Files selected for processing (1)
  • sensor/common/scan/scan_test.go

Included review availability: Your plan provides up to 4 included reviews per hour; 2 remain after this review.


📝 Summary

Summary by CodeRabbit

  • Bug Fixes

    • Improved scanner client handling to prevent image-analysis attempts when no supported scanner is available.
    • Ensured image analysis consistently uses the selected scanner client, preventing intermittent failures.
  • Changes

    • Scanner connectivity now uses Scanner V4 exclusively.
    • Removed legacy Scanner V2 connection and image-analysis support.
    • Added clearer warnings when Scanner V4 is unavailable or unsupported.

Walkthrough

The change removes Scanner V2 support, restricts singleton creation to Scanner V4, and passes one captured scanner client through image analysis.

Changes

Scanner client flow

Layer / File(s) Summary
Scanner V4-only client selection
sensor/common/scannerclient/grpc_client.go, sensor/common/scannerclient/singleton.go
Scanner V2 dialing and image analysis methods were removed. The singleton returns nil when Scanner V4 is disabled or unsupported, and otherwise creates a Scanner V4 client.
Image analysis client propagation
sensor/common/scan/scan.go
Image enrichment stores the singleton result, checks it for nil, and passes the captured client to fetchImageAnalysis and scanImg.
Regression coverage
sensor/common/scan/scan_test.go
The test verifies that the singleton is called once and that the captured client is passed to the scan operation.

Priority: ➖ Normal

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Bug fix

Suggested reviewers: alkmim

Merge Risk: ⚪ Minimal · up to d46f9

The captured-client regression test covers the intended nil-client edge case. No merge-blocking issue is identified.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 1 functions across 3 files.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Title check ✅ Passed The title clearly identifies the primary change: preventing delegated scan hangs when Scanner V2 is unavailable.
Description check ✅ Passed The description explains the problem, the Scanner V2 removal, the nil-pointer fix, testing coverage, and validation steps. The CI inspection checkbox is not selected, although the validation section s…
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch dc/dele-scan-no-hang

Comment @coderabbitai help to get the list of available commands.

@codecov

codecov Bot commented Sep 14, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 35.71429% with 9 lines in your changes missing coverage. Please review.
✅ Project coverage is 51.80%. Comparing base (e89ea29) to head (d46f942).
⚠️ Report is 10 commits behind head on master.

Files with missing lines Patch % Lines
sensor/common/scannerclient/singleton.go 0.00% 9 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master   #22836      +/-   ##
==========================================
- Coverage   51.83%   51.80%   -0.03%     
==========================================
  Files        2901     2901              
  Lines      182807   182763      -44     
==========================================
- Hits        94749    94681      -68     
- Misses      79770    79773       +3     
- Partials     8288     8309      +21     
Flag Coverage Δ
go-unit-tests 51.80% <35.71%> (-0.03%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@github-actions

Copy link
Copy Markdown
Contributor

/konflux-retest checks

2 similar comments
@github-actions

Copy link
Copy Markdown
Contributor

/konflux-retest checks

@github-actions

Copy link
Copy Markdown
Contributor

/konflux-retest checks

@github-actions

Copy link
Copy Markdown
Contributor

🚀 Build Images Ready

Images are ready for commit d46f942. To use with deploy scripts:

export MAIN_IMAGE_TAG=5.0.x-298-gd46f9423ad

// Check if there is a local Scanner.
// No need to continue if there is no local Scanner.
if s.scannerClientSingleton() == nil {
scannerClient := s.scannerClientSingleton()

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.

Looking at all of these changes in this file - is there actually any change happening here? If I'm reading this all correctly aren't both implementations doing the exact same thing.

I'll admit the new way feels cleaner and more readable (and doesn't rely on implicit global state) but I just want to make sure I'm not missing something :)

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.

Oh, nvm - I see that this is the fix for the TOCTOU mentioned.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

s.scannerClientSingleton() could return non-nil on the first invocation and nil on the second invocation in scanImage which would cause a panic. This PR re-uses the returned object to avoid that.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants