Skip to content

Harden task-drain loop: null safety and cached proxy lookups#1

Merged
cgfixit merged 1 commit into
mainfrom
optimize/script-robustness
Jun 30, 2026
Merged

Harden task-drain loop: null safety and cached proxy lookups#1
cgfixit merged 1 commit into
mainfrom
optimize/script-robustness

Conversation

@cgfixit

@cgfixit cgfixit commented Jun 30, 2026

Copy link
Copy Markdown
Owner

Summary

  • $ErrorActionPreference = 'Stop' inside the try block so errors in Disable-VBRViProxy, Enable-VBRViProxy, and service operations propagate to the catch block instead of silently continuing under the default Continue preference.
  • Null-safe property access in the drain loop: checks $task.Info and $task.Info.WorkDetails before accessing SourceProxyId, preventing NullReferenceException when a task has incomplete metadata.
  • Guard empty sessions: wraps Get-VBRTaskSession pipeline in a null check so it doesn't error when no backup sessions are active.
  • Cached proxy ID lookup: replaces the per-iteration Get-VBRViProxy | Where-Object call with a pre-built $ProxyIdSet hashtable. This eliminates a redundant VBR API round-trip on every 30-second poll cycle during drain waits — meaningful in environments with many proxies or slow VBR API responses.

Motivation

The drain loop is the most latency-sensitive part of the script (runs repeatedly for up to 30+ minutes). The original code made an extra Get-VBRViProxy API call every poll cycle just to resolve a proxy ID it already had, and could crash on null WorkDetails for certain task types (e.g., Instant Recovery sessions).

Test plan

  • Run Pre stage with active backup jobs on target proxies — verify drain loop polls correctly and exits when tasks complete
  • Run Pre stage with no active jobs — verify it skips drain immediately
  • Intentionally trigger an error in Disable-VBRViProxy — verify it now exits with code 20 instead of silently continuing

Generated by Claude Code

…xy IDs

- Set $ErrorActionPreference = 'Stop' inside the try block so unhandled
  errors in disable/enable/service operations bubble up to the catch
  instead of silently continuing.

- Guard against null dereference in drain loop: check $task.Info and
  $task.Info.WorkDetails before accessing SourceProxyId.

- Guard $runningSessions being null before piping to Get-VBRTaskSession,
  preventing pipeline errors when no sessions are active.

- Replace per-iteration Get-VBRViProxy lookup with a pre-built hashtable
  ($ProxyIdSet) keyed by proxy ID. Eliminates a redundant VBR API call
  on every poll cycle, reducing API load during drain waits.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01DDj3zuCAvrsZcQKsPpPHvA
@github-actions

Copy link
Copy Markdown

Dependency Review

✅ No vulnerabilities or license issues or OpenSSF Scorecard issues found.

Scanned Files

None

@cgfixit cgfixit mentioned this pull request Jun 30, 2026
3 tasks
@cgfixit cgfixit marked this pull request as ready for review June 30, 2026 03:52
@cgfixit cgfixit merged commit 56c7ce0 into main Jun 30, 2026
7 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