Use flock instead of lsof command in run-command-shim to prevent run commands hanging due to lsof command hanging#70
Open
viveklingaiah wants to merge 5 commits into
Open
Use flock instead of lsof command in run-command-shim to prevent run commands hanging due to lsof command hanging#70viveklingaiah wants to merge 5 commits into
viveklingaiah wants to merge 5 commits into
Conversation
alsanmsft
approved these changes
Jan 8, 2026
D1v38om83r
requested changes
Feb 9, 2026
| set -x | ||
| while (( retry_attempts < 10 )); do | ||
| # Acquire the exclusive (-x) and non-blocking (-n) lock on the lock file and execute $commandToExecute(side note: flock is part of util-linux package and is available by default on most Linux distros) | ||
| flock -x -n "$LOCKFILE" -c "$commandToExecute" |
Collaborator
There was a problem hiding this comment.
Add a condition to check if flock is available on the host OS. If its not available, I think we should either fallback to lsof, or forego checking for file lock altogether and let the error bubble up in the status file.
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.
Problem(s):
ICM incidents mentioned here Task 34627514: Investigate RCv2 Linux NOT using lsof command OR using alternatives (lsof command hanging)
Background:
Solution
Sample execution from log:
2025-12-17T21:16:40.356264Z INFO ExtHandler [Microsoft.Azure.Extensions.Edp.RunCommandHandlerLinuxTest.RC1218_7-1.14.0] Command: bin/run-command-shim enable
[stdout]
flock -x -n ./run-command-handler.lock -c 'nohup /var/lib/waagent/Microsoft.Azure.Extensions.Edp.RunCommandHandlerLinuxTest-1.14.0/bin/run-command-handler enable &'
'+ flock_status=0
'+ '[' 0 -eq 1 ']'
'+ '[' 0 -eq 0 ']'
'+ LOCK_ACQUIRED=1
'+ echo 'Lock acquired on file ./run-command-handler.lock and executed command nohup /var/lib/waagent/Microsoft.Azure.Extensions.Edp.RunCommandHandlerLinuxTest-1.14.0/bin/run-command-handler enable & successfully. Exiting.'
Lock acquired on file ./run-command-handler.lock and executed command nohup /var/lib/waagent/Microsoft.Azure.Extensions.Edp.RunCommandHandlerLinuxTest-1.14.0/bin/run-command-handler enable & successfully. Exiting.
'+ break
'+ set +x