@@ -48,7 +48,7 @@ function async_log {
48
48
command=$( iniget $inifile job command | tr ' #' ' -' )
49
49
message=$( echo " $message " | sed " s#%command#$command #g" )
50
50
51
- echo " [Async ${name} :${pid} ]: $message "
51
+ echo " [$BASHPID Async ${name} :${pid} ]: $message "
52
52
}
53
53
54
54
# Inner function that actually runs the requested task. We wrap it like this
@@ -57,7 +57,7 @@ function async_log {
57
57
function async_inner {
58
58
local name=" $1 "
59
59
local rc
60
- local fifo=${DEST} /async/${name} .fifo
60
+ local fifo=" ${DEST} /async/${name} .fifo"
61
61
shift
62
62
set -o xtrace
63
63
if $* > ${DEST} /async/${name} .log 2>&1 ; then
@@ -116,6 +116,24 @@ function async_runfunc {
116
116
async_run $1 $*
117
117
}
118
118
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
+
119
137
# Wait for an async future to complete. May return immediately if already
120
138
# complete, or of the future has already been waited on (avoid this). May
121
139
# block until the future completes.
@@ -129,18 +147,18 @@ function async_wait {
129
147
for name in $* ; do
130
148
running=$( ls ${DEST} /async/* .ini 2> /dev/null | wc -l)
131
149
inifile=" ${DEST} /async/${name} .ini"
132
- fifo=${DEST} /async/${name} .fifo
150
+ fifo=" ${DEST} /async/${name} .fifo"
133
151
134
152
if pid=$( async_pidof " $name " ) ; then
135
153
async_log " $name " " Waiting for completion of %command" \
136
- " ($running other jobs running)"
154
+ " running on PID $pid ($running other jobs running)"
137
155
time_start async_wait
138
156
if [[ " $pid " != " self" ]]; then
139
157
# Signal the child to go ahead and exit since we are about to
140
158
# wait for it to collect its status.
141
- echo " Signaling exit"
159
+ async_log " $name " " Signaling child to exit"
142
160
echo WAKEUP > $fifo
143
- echo " Signaled"
161
+ async_log " $name " " Signaled"
144
162
# Do not actually call wait if we ran synchronously
145
163
if wait $pid ; then
146
164
rc=0
@@ -161,6 +179,7 @@ function async_wait {
161
179
" $rc in $runtime seconds"
162
180
rm -f $inifile
163
181
if [ $rc -ne 0 ]; then
182
+ async_wait_dump $pid
164
183
echo Stopping async wait due to error: $*
165
184
break
166
185
fi
0 commit comments