This blog is something different than usual. Normally my blog focusses on implementations with step by step context. This time, I’m sharing a story about some troubleshooting I’ve did on an Azure Virtual Desktop environment.
Recently i found out that an AVD environment we’re building does not disconnect and logoff idle sessions from hosts. We configured policies to get rid of these disconnected sessions but somehow, it does not execute the logoff.. Sessions stay in a disconnected state forever which makes the Pay-as-you-Go/Scaling absolutely useless.
The organization has multiple different idle timers. This means we cannot set it on device level and are required to use the (User) equivalent of this policy. In general this is not an issue at all. As long as your profiling is in place. <- Remember this!
After troubleshooting i found out the exact cause of the issue in our situation. The policies are assigned on user objects and are deployed in user context. The following registry settings are created at/after first logon:
- HKEY_CURRENT_USER\Software\Policies\Microsoft\Windows NT\Terminal Services\MaxIdleTime
- HKEY_CURRENT_USER\Software\Policies\Microsoft\Windows NT\Terminal Services\MaxDisconnectionTime
I asked myself the question why this did not result in sessions being disconnected and eventually being logged off!?
The problem here is that we have a pretty big hostpool with many sessionhosts without FSLogix (for now). This means that a user has a local profile on every sessionhost, which is being created as soon as they have a session for the first time they logon to a specific sessionhost. This could take many many days before a user has a local profile on every sessionhost. But if they have, it works..
Now comes the fun part. We are replacing all sessionhosts every month with the newest image from the image builder and thus we start over again with new local profiles on all sessionhosts. Which does mean that we are in a loop every month….
Solution
The solution here is to have (for example) FSLogix for your environment to take this profile with you around every sessionhost. This might result in not having a working idle timer the first session but for sure it does the second time no matter on which sessionhost you’re logged on.
Since the profiles on this environment are small and not growing over time we don’t need that much storage for these profiles. The costs of the storage account is way less than we can save with our scaling plan. No brainer!
Workaround
If you are not willing to implement FSLogix for your environment there’s a ugly workaround to think about. You could use PowerShell to logoff all sessions with disconnected state at certain times. This script could run via an scheduled pipeline, azure automation account, etc.. you decide!
$HPRG = "RG-HP-AVD"
$HPNAME = "HP-AVD"
Get-AzWvdUserSession -ResourceGroupName $HPRG -HostPoolName $HPNAME | Where-Object { $_.SessionState -eq 'Disconnected' } | Remove-AzWvdUserSession