DEV Community

Cover image for Azure Devops Pipelines — Could not get lock /var/lib/dpkg/lock-frontend
Andy Roberts
Andy Roberts

Posted on • Originally published at andyr8939.Medium on

Azure Devops Pipelines — Could not get lock /var/lib/dpkg/lock-frontend

Azure Devops Pipelines — Could not get lock /var/lib/dpkg/lock-frontend

I’ve been using Azure DevOps Pipelines to build our Azure Infrastructure with Terraform for nearly 9 months now and its been pretty much rock solid. However, recently all of a sudden my pipelines started failing if I ran more than 1 build at a time, and all gave this error.

E: Could not get lock /var/lib/dpkg/lock-frontend - open (11: Resource temporarily unavailable) 
E: Unable to acquire the dpkg frontend lock (/var/lib/dpkg/lock-frontend), is another process using it?
Enter fullscreen mode Exit fullscreen mode

This was happening at the part of the pipeline where I install some dependencies I need on the ubuntu agent, mainly jq, unzip, zip etc. It was only happening when I ran multiple pipelines at once, so my self hosted VM Scale Sets agents ramped up. If it was a single deployment it was fine.

Seeing your pipelines do this when you are under the pump to deliver a lot of changes is frustrating.

Solution

It turned out to be fairly simple. When the VM Scale Set Instance was starting, something which I think was the Azure DevOps Extension, was using apt-get to get updates, which meant my dependency section couldn’t run apt-get due to the lock and crashed out.

To fix it I added in a wait loop to my dependencies section in the pipeline with the below.

_# Install dependencies in the agent pool server_

- task: Bash@3

inputs:

targetType: 'inline'

script: |

until sudo apt-get -y update && sudo apt-get install unzip zip jq -y

do

echo "Try again"

sleep 2

done

displayName: 'Install Dependencies'
Enter fullscreen mode Exit fullscreen mode

All that is doing is trying to get the packages with apt-get, and if it can’t do it because of the lock, wait 2 seconds and try again until it can. Simple, but very effective.

So now instead of my dependency check crashing out in <1s if there was a lock, it typically hits a lock for 10 seconds or so, then completes fine and I have had 100% pipeline success since.

Hope that helps!

Andy

Originally published at https://www.andyroberts.nz on September 10, 2021.

Sentry image

See why 4M developers consider Sentry, “not bad.”

Fixing code doesn’t have to be the worst part of your day. Learn how Sentry can help.

Learn more

Top comments (0)

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

AWS GenAI LIVE!

GenAI LIVE! is a dynamic live-streamed show exploring how AWS and our partners are helping organizations unlock real value with generative AI.

Tune in to the full event

DEV is partnering to bring live events to the community. Join us or dismiss this billboard if you're not interested. ❤️