Skip to content

Commit 51e3845

Browse files
committed
Add some debug to async_wait failures
This dumps some data in the case where we fail to wait for a child pid to help debug what is going on. This also cleans up a few review comments from the actual fix. Change-Id: I7b58ce0cf2b41bdffa448973edb4c992fe5f730c Related-Bug: #1923728
1 parent aa5c387 commit 51e3845

File tree

1 file changed

+25
-6
lines changed

1 file changed

+25
-6
lines changed

inc/async

+25-6
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ function async_log {
4848
command=$(iniget $inifile job command | tr '#' '-')
4949
message=$(echo "$message" | sed "s#%command#$command#g")
5050

51-
echo "[Async ${name}:${pid}]: $message"
51+
echo "[$BASHPID Async ${name}:${pid}]: $message"
5252
}
5353

5454
# Inner function that actually runs the requested task. We wrap it like this
@@ -57,7 +57,7 @@ function async_log {
5757
function async_inner {
5858
local name="$1"
5959
local rc
60-
local fifo=${DEST}/async/${name}.fifo
60+
local fifo="${DEST}/async/${name}.fifo"
6161
shift
6262
set -o xtrace
6363
if $* >${DEST}/async/${name}.log 2>&1; then
@@ -116,6 +116,24 @@ function async_runfunc {
116116
async_run $1 $*
117117
}
118118

119+
# Dump some information to help debug a failed wait
120+
function async_wait_dump {
121+
local failpid=$1
122+
123+
echo "=== Wait failure dump from $BASHPID ==="
124+
echo "Processes:"
125+
ps -f
126+
echo "Waiting jobs:"
127+
for name in $(ls ${DEST}/async/*.ini); do
128+
echo "Job $name :"
129+
cat "$name"
130+
done
131+
echo "Failed PID status:"
132+
sudo cat /proc/$failpid/status
133+
sudo cat /proc/$failpid/cmdline
134+
echo "=== End wait failure dump ==="
135+
}
136+
119137
# Wait for an async future to complete. May return immediately if already
120138
# complete, or of the future has already been waited on (avoid this). May
121139
# block until the future completes.
@@ -129,18 +147,18 @@ function async_wait {
129147
for name in $*; do
130148
running=$(ls ${DEST}/async/*.ini 2>/dev/null | wc -l)
131149
inifile="${DEST}/async/${name}.ini"
132-
fifo=${DEST}/async/${name}.fifo
150+
fifo="${DEST}/async/${name}.fifo"
133151

134152
if pid=$(async_pidof "$name"); then
135153
async_log "$name" "Waiting for completion of %command" \
136-
"($running other jobs running)"
154+
"running on PID $pid ($running other jobs running)"
137155
time_start async_wait
138156
if [[ "$pid" != "self" ]]; then
139157
# Signal the child to go ahead and exit since we are about to
140158
# wait for it to collect its status.
141-
echo "Signaling exit"
159+
async_log "$name" "Signaling child to exit"
142160
echo WAKEUP > $fifo
143-
echo "Signaled"
161+
async_log "$name" "Signaled"
144162
# Do not actually call wait if we ran synchronously
145163
if wait $pid; then
146164
rc=0
@@ -161,6 +179,7 @@ function async_wait {
161179
"$rc in $runtime seconds"
162180
rm -f $inifile
163181
if [ $rc -ne 0 ]; then
182+
async_wait_dump $pid
164183
echo Stopping async wait due to error: $*
165184
break
166185
fi

0 commit comments

Comments
 (0)