Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix for text file busy error for custom-script-extension binary #153

Merged
merged 6 commits into from
Oct 7, 2019
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions misc/custom-script-shim
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,19 @@ write_status() {
fi
}

check_binary_write_lock() {
set +e # disable exit on non-zero return code
lsof_output="$(lsof ${bin})"
if [ "$?" -eq 0 ]; then
echo "${HANDLER_BIN} is open by the following processes: "
echo "${lsof_output}"
echo "attempting to kill processes with open file handles to ${HANDLER_BIN}"
# suppress output and errors in case process with file-handle is already dead and kill gets called without a process id
lsof -t ${bin} | xargs kill -9 > /dev/null 2>&1
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Given that this appears to be a race condition, I'm not sure we should do anything but log and add a bit of retry/wait logic here. There was speculation that waagent may be holding up the file - we don't want to kill that or any other critical process.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For now, let's hold off on killing any processes and see if the retries fix the problem. With this change, we'll also gather data about which processes are the culprits.

fi
set -e # re-enable exit on non-zero return code
}

if [ "$#" -ne 1 ]; then
echo "Incorrect usage."
echo "Usage: $0 <command>"
Expand All @@ -69,10 +82,12 @@ if [[ "$cmd" == "enable" ]]; then
# to detach from the handler process tree to avoid getting terminated
# after the 15-minute extension enabling timeout.
write_status
check_binary_write_lock
set -x
nohup "$bin" $@ &
else
# execute the handler process as a child process
check_binary_write_lock
set -x
"$bin" $@
fi