Skip to content

Commit 3cb2146

Browse files
authored
Fix Excessive CPU usage, fix --solo (#974)
1 parent 03448f4 commit 3cb2146

File tree

2 files changed

+12
-9
lines changed

2 files changed

+12
-9
lines changed

rootfs/templates/wrapper-body.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -588,6 +588,7 @@ function use() {
588588
)
589589

590590
if [ "$ONE_SHELL" = "true" ]; then
591+
[ -t 0 ] && DOCKER_EXEC_ARGS+=(-it)
591592
DOCKER_NAME="${DOCKER_NAME}-$(date +%d%H%M%S)"
592593
echo "# Starting single shell ${DOCKER_NAME} session from ${DOCKER_IMAGE}"
593594
echo "# Exposing port ${GEODESIC_PORT}"

rootfs/usr/local/sbin/shell-monitor

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,11 @@ wrapper_pids=()
66

77
# Function to count active shell sessions launched by wrapper
88
# Expensive, so run sparingly. Only needed to find new shells when they launch.
9-
count_shells() {
9+
shells_are_running() {
10+
# As a side effect, update the list of running shells
1011
wrapper_pids=($(list-wrapper-shells))
11-
echo "${#wrapper_pids[@]}"
12+
# Return true if there are any shells running
13+
[[ "${#wrapper_pids[@]}" -gt 0 ]]
1214
}
1315

1416
# Function to check if any registered shell has exited.
@@ -31,25 +33,25 @@ shell_has_exited() {
3133
# Function to kill all active shell sessions launched by wrapper.
3234
# This is the shutdown procedure, so we do not care about hogging the CPU.
3335
kill_shells() {
34-
for pid in $(list_wrapper_shells); do
36+
for pid in $(list-wrapper-shells); do
3537
kill -HUP $pid
3638
done
3739

3840
for i in {1..4}; do
39-
[ $(count_shells) -eq 0 ] && return 0
41+
shells_are_running || return 0
4042
sleep 1
4143
done
4244

43-
for pid in $(list_wrapper_shells); do
45+
for pid in $(list-wrapper-shells); do
4446
kill -TERM $pid
4547
done
4648

4749
for i in {1..3}; do
48-
[ $(count_shells) -eq 0 ] && return 0
50+
shells_are_running || return 0
4951
sleep 1
5052
done
5153

52-
for pid in $(list_wrapper_shells); do
54+
for pid in $(list-wrapper-shells); do
5355
kill -KILL $pid
5456
done
5557

@@ -62,7 +64,7 @@ trap 'kill_shells; exit $?' TERM HUP INT QUIT EXIT
6264
# Since we are waiting for something to happen, we can afford burn
6365
# up some CPU in order to be more responsive.
6466
i=0
65-
while [ $(count_shells) -eq 0 ]; do
67+
while ! shells_are_running; do
6668
sleep 0.5
6769
i=$((i + 1))
6870
if [ $i -ge 120 ]; then
@@ -87,7 +89,7 @@ while true; do
8789
while ! shell_has_exited; do
8890
sleep 0.67
8991
done
90-
[[ $(count_shells) -eq 0 ]] && break
92+
shells_are_running || break
9193
done
9294

9395
# Clean up and exit

0 commit comments

Comments
 (0)