Harden task-drain loop: null safety and cached proxy lookups#1
Merged
Conversation
…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
Dependency Review✅ No vulnerabilities or license issues or OpenSSF Scorecard issues found.Scanned FilesNone |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
$ErrorActionPreference = 'Stop'inside the try block so errors inDisable-VBRViProxy,Enable-VBRViProxy, and service operations propagate to the catch block instead of silently continuing under the defaultContinuepreference.$task.Infoand$task.Info.WorkDetailsbefore accessingSourceProxyId, preventingNullReferenceExceptionwhen a task has incomplete metadata.Get-VBRTaskSessionpipeline in a null check so it doesn't error when no backup sessions are active.Get-VBRViProxy | Where-Objectcall with a pre-built$ProxyIdSethashtable. 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-VBRViProxyAPI call every poll cycle just to resolve a proxy ID it already had, and could crash on nullWorkDetailsfor certain task types (e.g., Instant Recovery sessions).Test plan
Prestage with active backup jobs on target proxies — verify drain loop polls correctly and exits when tasks completePrestage with no active jobs — verify it skips drain immediatelyDisable-VBRViProxy— verify it now exits with code 20 instead of silently continuingGenerated by Claude Code