Skip to content

Commit 04390af

Browse files
committed
Fix 'echo: write error: Broken pipe' on Alpine (#37)
Replace process-substitution FIFOs (read < <(func)) with here-strings (read <<< "$(func)") in all stats-gathering call sites. The FIFO pattern can race on Alpine/busybox: read closes the pipe before the function's echo completes, triggering SIGPIPE.
1 parent 7210c0e commit 04390af

1 file changed

Lines changed: 7 additions & 7 deletions

File tree

mtproxymax.sh

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1310,7 +1310,7 @@ get_cumulative_proxy_stats() {
13101310
[[ "${snap_out:-0}" =~ ^[0-9]+$ ]] || snap_out=0
13111311

13121312
local live_in=0 live_out=0 conns=0
1313-
read -r live_in live_out conns < <(get_proxy_stats)
1313+
read -r live_in live_out conns <<< "$(get_proxy_stats)"
13141314

13151315
local delta_in=$((live_in - snap_in))
13161316
local delta_out=$((live_out - snap_out))
@@ -1371,7 +1371,7 @@ get_cumulative_user_stats() {
13711371

13721372
# Get current live Prometheus values
13731373
local live_in=0 live_out=0 live_conns=0
1374-
read -r live_in live_out live_conns < <(get_user_stats "$user" 2>/dev/null)
1374+
read -r live_in live_out live_conns <<< "$(get_user_stats "$user" 2>/dev/null)"
13751375

13761376
# Compute delta since last save
13771377
# If live < snapshot, a restart happened — delta is just the live value
@@ -5013,7 +5013,7 @@ show_status_json() {
50135013
if is_proxy_running; then
50145014
status="running"
50155015
uptime_secs=$(get_proxy_uptime 2>/dev/null) || uptime_secs=0
5016-
read -r traffic_in traffic_out connections < <(get_cumulative_proxy_stats)
5016+
read -r traffic_in traffic_out connections <<< "$(get_cumulative_proxy_stats)"
50175017
fi
50185018

50195019
_load_all_cumulative_user_stats 2>/dev/null
@@ -5202,7 +5202,7 @@ show_status() {
52025202
up_secs=$(get_proxy_uptime)
52035203
uptime_str=$(format_duration "$up_secs")
52045204

5205-
read -r traffic_in traffic_out connections < <(get_cumulative_proxy_stats)
5205+
read -r traffic_in traffic_out connections <<< "$(get_cumulative_proxy_stats)"
52065206
else
52075207
status_str=$(draw_status stopped)
52085208
uptime_str=""
@@ -5592,7 +5592,7 @@ cli_main() {
55925592
echo ""
55935593
draw_header "TRAFFIC"
55945594
local t_in t_out conns
5595-
read -r t_in t_out conns < <(get_cumulative_proxy_stats)
5595+
read -r t_in t_out conns <<< "$(get_cumulative_proxy_stats)"
55965596
# Batch-load all user stats
55975597
_load_all_cumulative_user_stats 2>/dev/null
55985598
echo ""
@@ -5980,7 +5980,7 @@ show_main_menu() {
59805980
local up_secs=$(( $(date +%s) - _cached_start_epoch ))
59815981
uptime_str=$(format_duration "$up_secs")
59825982
# Parse all stats fields in a single read (no awk subprocesses)
5983-
read -r traffic_in traffic_out connections < <(get_cumulative_proxy_stats)
5983+
read -r traffic_in traffic_out connections <<< "$(get_cumulative_proxy_stats)"
59845984
else
59855985
status_str=$(draw_status stopped)
59865986
uptime_str=""
@@ -6542,7 +6542,7 @@ show_traffic_menu() {
65426542
fi
65436543

65446544
local t_in t_out conns
6545-
read -r t_in t_out conns < <(get_cumulative_proxy_stats)
6545+
read -r t_in t_out conns <<< "$(get_cumulative_proxy_stats)"
65466546

65476547
# Batch-load all user stats in one pass
65486548
_load_all_cumulative_user_stats 2>/dev/null

0 commit comments

Comments
 (0)