@@ -6,6 +6,7 @@ NS="${NS:-default}" # Override with --ns
66POD_NAME=" " # Override with --pod
77SLEEP_BETWEEN=0.2
88CHECK_RETRIES=25 # 25 * 0.2s = 5s
9+ WS_CHECK_RETRIES=50 # 50 * 0.2s = 10s (WebSocket may take longer)
910PORTS_ENV_FILE=" ${PORTS_ENV_FILE:- $(dirname " $0 " )/ .pf-env} "
1011
1112usage () {
@@ -41,6 +42,7 @@ start_pf() {
4142 local mapping=" $2 " # <local>:<remote>
4243 local local_port=" ${mapping%%:* } "
4344 local remote_port=" ${mapping##*: } "
45+ local retries=" ${3:- $CHECK_RETRIES } " # Optional custom retry count
4446
4547 free_port " $local_port "
4648
@@ -53,7 +55,7 @@ start_pf() {
5355
5456 # Health check: wait for local port to open
5557 local ok=0
56- for _ in $( seq 1 $CHECK_RETRIES ) ; do
58+ for _ in $( seq 1 " $retries " ) ; do
5759 # Prefer nc if available; otherwise use bash's /dev/tcp
5860 if command -v nc > /dev/null 2>&1 ; then
5961 if nc -z 127.0.0.1 " $local_port " > /dev/null 2>&1 ; then
@@ -73,7 +75,7 @@ start_pf() {
7375 done
7476
7577 if [[ $ok -eq 1 ]]; then
76- log " Forwarded $target (local $mapping ) "
78+ log " ✓ Forwarded $target → 127.0.0.1: $mapping "
7779 # Record ports to env file for consumers (e.g., CI step/tests)
7880 case " $remote_port " in
7981 8899)
@@ -87,7 +89,7 @@ start_pf() {
8789 esac
8890 return 0
8991 else
90- err " Failed to forward $target (local $mapping ) ; killing pid $pf_pid "
92+ err " ✗ Failed to forward $target → 127.0.0.1: $mapping after ${retries} retries ; killing pid $pf_pid "
9193 kill -9 " $pf_pid " > /dev/null 2>&1 || true
9294 # Surface port-forward logs to help debugging
9395 if [[ -f " $log_file " ]]; then
@@ -99,12 +101,18 @@ start_pf() {
99101 fi
100102}
101103
104+ # Start WebSocket port-forward with longer timeout
105+ start_ws_pf () {
106+ start_pf " $1 " " $2 " " $WS_CHECK_RETRIES "
107+ }
108+
102109# Try a list of local ports for a given remote port and record the first success
103110start_pf_any () {
104111 local target=" $1 "
105112 local remote_port=" $2 "
106113 shift 2
107114 local candidate
115+ log " Trying alternate ports for $target :$remote_port → $* "
108116 for candidate in " $@ " ; do
109117 if start_pf " $target " " ${candidate} :${remote_port} " ; then
110118 return 0
@@ -154,15 +162,23 @@ success=0
154162# Try pod first; if it fails, fall back to service/solana-genesis
155163( start_pf " pods/$POD_NAME " " 8899:8899" || start_pf " service/solana-genesis" " 8899:8899" ) && (( success++ )) # Solana RPC
156164
157- # WebSocket: try default 8900 locally; if bind fails, try alternates and record selected port
158- if start_pf " pods/$POD_NAME " " 8900:8900" || start_pf " service/solana-genesis" " 8900:8900" ; then
165+ # WebSocket: prefer pod over service for headless services
166+ # Try pod first, then try alternates if it fails
167+ log " Setting up WebSocket port-forward (8900) with extended timeout..."
168+ if start_ws_pf " pods/$POD_NAME " " 8900:8900" ; then
169+ log " ✓ WebSocket port-forward established on default port 8900"
170+ (( success++ ))
171+ elif start_pf_any " pods/$POD_NAME " 8900 8910 18900 19000 29000; then
172+ log " ✓ WebSocket port-forward established on alternate port"
173+ (( success++ ))
174+ elif start_ws_pf " service/solana-genesis" " 8900:8900" ; then
175+ log " ✓ WebSocket port-forward established via service on port 8900"
176+ (( success++ ))
177+ elif start_pf_any " service/solana-genesis" 8900 8910 18900 19000 29000; then
178+ log " ✓ WebSocket port-forward established via service on alternate port"
159179 (( success++ ))
160180else
161- # Try alternate local ports mapping to remote 8900
162- if start_pf_any " pods/$POD_NAME " 8900 8910 18900 19000 29000 || \
163- start_pf_any " service/solana-genesis" 8900 8910 18900 19000 29000; then
164- (( success++ ))
165- fi
181+ err " ✗ Failed to establish WebSocket port-forward on any port"
166182fi
167183start_pf " pods/$POD_NAME " " 8001:8001" && (( success++ )) # Exposer
168184start_pf " pods/$POD_NAME " " 9900:9900" && (( success++ )) # Faucet
0 commit comments