-
Notifications
You must be signed in to change notification settings - Fork 59
Description
Prerequisites
- Write a descriptive title.
- Make sure you are able to repro it on the latest version
- Search the existing issues.
Summary
Invoke-DscCacheRefresh targeted module cache refreshes using $Module, has a number of bugs which can lead to incomplete or broken cache state. Once the cache enters this state there is no recovery, requiring either manual reset or triggering cache refresh and $Module not being passed for a full refresh.
These issues were discovered during efforts to understand how cache refresh worked while troubleshooting #745. It's possible the cache refresh was designed for a time when DSC v3 worked differently. With current behaviour, targeted refreshes add significant complexity, it could do with a review of whether it's still needed.
- Cache refreshes only return
$Module, fixed in Fix resourceCache to return proper modules when PS modules are installed during run #748. Refreshes would overwrite the cache with an incomplete cache. - Changes triggering
PSModulePathrefreshes are not included in the cache refresh, proposed fix fix: win_psDscAdapter targeted module cache refreshes #787 - Stale resource entries will remain in the cache if they are not included in
$Module. - Refreshes targeting only
PSDesiredStateConfigurationoverwrites cache with incomplete cache. - Refreshes containing
PSDesiredStateConfigurationincorrectly handlesPSDesiredStateConfiguration/SignatureValidationandPSDesiredStateConfiguration/File. - Refreshes containing duplicate module names result in duplicate resource cache entries.
- Incompatible schema refresh retains
ResourceCacheentries with potentially incompatible schema. - If the cache is non-existent or empty, a partial/incomplete cache is built.
If the cache is cold (missing, empty, or schema-invalid), a full refresh would guarantee correctness. If PSModulePath changes also force full refreshes, only stale resource entries would result in a targeted refresh. It wouldn't be too far from removing it altogether.
Another approach would be to exploit how get, set and test are always called with $Module and provide incremental cache recovery. It's not perfect but aligns the most with the current code. An implementation is linked in the next section.
A redesign of the cache could ensure cold starts began with a full refresh and stale resource entries or stale paths are handled differently allowing an optimised targeted module refresh.
Steps to reproduce
Instead of providing repros for every case, this commit 27a3b6b, which tries to make targeted module refreshes safer, can be used to review this issue.
Expected behavior
For the cache state to be consistent with the module environmentActual behavior
The cache is considered valid but the state can be:
- Incomplete/partially complete
- Contain duplicate resource entries
- Retain stale entriesError details
2025-05-10T10:21:07.367034Z DEBUG dsc_lib::dscresources::command_resource: 902: PID 3456: Reading from Get-DscResource cache file C:\Users\Administrator\AppData\Local\dsc\WindowsPSAdapterCache.json
2025-05-10T10:21:07.411037Z DEBUG dsc_lib::dscresources::command_resource: 902: PID 3456: Checking cache for stale entries
2025-05-10T10:21:07.900558Z DEBUG dsc_lib::dscresources::command_resource: 902: PID 3456: Checking cache for stale PSModulePath
2025-05-10T10:21:07.990651Z DEBUG dsc_lib::dscresources::command_resource: 902: PID 3456: PSModulePath diff ''
2025-05-10T10:21:08.001003Z ERROR dsc_lib::dscresources::command_resource: 896: PID 3456: DSC resource 'xPSDesiredStateConfiguration/xWindowsFeature' module not found.
2025-05-10T10:21:08.048023Z DEBUG dsc_lib::dscresources::command_resource: 660: Process 'powershell' id 3456 exited with code 1
2025-05-10T10:21:08.049577Z ERROR dsc::subcommand: 106: Error: Command: Resource 'powershell' [exit code 1] manifest description: ErrorEnvironment data
Name Value
---- -----
PSVersion 5.1.26100.3624
PSEdition Desktop
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0...}
BuildVersion 10.0.26100.3624
CLRVersion 4.0.30319.42000
WSManStackVersion 3.0
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1Version
3.1.0-preview.5
Visuals
No response