azure-pipelines-agent: Failure to get lock fails installation

https://github.com/microsoft/azure-pipelines-agent/blob/b93f8f1f4e53ddf5d9cd25090db6f71b092d177c/src/Agent.Listener/Configuration.Windows/NativeWindowsServiceHelper.cs#L522

Referring to the line above, if the SCM is busy at the time the agent tries to register/update properties, the installation doesn’t complete , and doesn’t wait/retry to get a lock. We are hitting this constantly when spinning up new agents in a scale set using the method described here: https://docs.microsoft.com/en-us/azure/devops/pipelines/agents/scale-set-agents?view=azure-devops using the scripts from Microsoft found here: https://github.com/actions/virtual-environments/tree/main/images

The image is based on Windows 2019 (10.0.17763), which makes this all the stranger, since the documentation for the function call here: https://docs.microsoft.com/en-us/windows/win32/api/winsvc/nf-winsvc-lockservicedatabase says: “[As of Windows Vista, this function is provided for application compatibility and has no effect on the database.]”.

The relevant log info:

[2021-10-03 23:04:29Z INFO Terminal] WRITE LINE: Service vstsagent.Ucss.xxx-azdevops-pool.azdevops-1234XX successfully installed
[2021-10-03 23:04:29Z ERR  Agent] System.InvalidOperationException: Failed to Lock Service Database for Write
   at Microsoft.VisualStudio.Services.Agent.Listener.Configuration.NativeWindowsServiceHelper.InstallService(String serviceName, String serviceDisplayName, String logonAccount, String logonPassword)
   at Microsoft.VisualStudio.Services.Agent.Listener.Configuration.WindowsServiceControlManager.ConfigureService(AgentSettings settings, CommandSettings command)
   at Microsoft.VisualStudio.Services.Agent.Listener.Configuration.ConfigurationManager.ConfigureAsync(CommandSettings command)
   at Microsoft.VisualStudio.Services.Agent.Listener.Agent.ExecuteCommand(CommandSettings command)
[2021-10-03 23:04:29Z ERR  Terminal] WRITE ERROR: Failed to Lock Service Database for Write

See also: https://github.com/microsoft/azure-pipelines-agent/issues/3063

About this issue

  • Original URL
  • State: closed
  • Created 5 years ago
  • Reactions: 1
  • Comments: 15 (3 by maintainers)

Most upvoted comments

Hi everyone!

AFAIK this bug should be resolved in the latest version https://github.com/microsoft/azure-pipelines-agent/releases/tag/v2.217.2

Correct, this fix was released in version 2.217.2. Could you confirm if this fix solved the issue for you? Thanks!

Yes, I havent seen this issue with the new release. Thanks!

An issue for me too (Failed to Lock Service Database for Write). Also running on W2019 if that is relevant. Using the script generated from Azure Devops when adding VMs in the devops environment. Run as part of the installation of the VM as an extension. Works most time but fails annoyingly often anyway.

This is not stale

The issue also sporadically occurs on Windows Server 2022 (just got it on 10.0.20348 Build 350) and makes automated deploying of build agents a pain.