@@ -628,12 +628,18 @@ tasks:
628628 PORT_FORWARD_PID=$!
629629 echo "Port forwarding set up with PID: $PORT_FORWARD_PID"
630630
631+ # Verify the PID was captured properly
632+ if [ -z "$PORT_FORWARD_PID" ] || [ "$PORT_FORWARD_PID" -eq "0" ]; then
633+ echo "ERROR: Failed to capture port-forward process PID"
634+ exit 1
635+ fi
636+
631637 # Give port-forward more time to establish
632638 echo "Waiting for port-forward to establish..."
633639 sleep 5
634640
635641 # Check if port-forward process is still running
636- if ! ps -p $PORT_FORWARD_PID > /dev/null; then
642+ if ! ps -p $PORT_FORWARD_PID > /dev/null 2>&1 ; then
637643 echo "ERROR: Port forwarding process died. Check the logs:"
638644 cat $PORT_FORWARD_LOG
639645 exit 1
@@ -658,7 +664,7 @@ tasks:
658664 echo "Connection attempt $CONN_RETRY_COUNT failed, retrying in 5 seconds..."
659665
660666 # Check if port-forward is still running
661- if ! ps -p $PORT_FORWARD_PID > /dev/null; then
667+ if ! ps -p $PORT_FORWARD_PID > /dev/null 2>&1 ; then
662668 echo "ERROR: Port forwarding process died during connection attempts."
663669 echo "Port forwarding log:"
664670 cat $PORT_FORWARD_LOG
@@ -667,7 +673,15 @@ tasks:
667673 echo "Attempting to restart port forwarding..."
668674 kubectl port-forward -n {{.NAMESPACE}} $SERVICE_NAME {{.PORT}}:5000 > $PORT_FORWARD_LOG 2>&1 &
669675 PORT_FORWARD_PID=$!
676+
677+ # Verify the PID was captured properly after restart
678+ if [ -z "$PORT_FORWARD_PID" ] || [ "$PORT_FORWARD_PID" -eq "0" ]; then
679+ echo "ERROR: Failed to capture restarted port-forward process PID"
680+ exit 1
681+ fi
682+
670683 echo "Restarted port forwarding with PID: $PORT_FORWARD_PID"
684+ sleep 5 # Give the new port-forward time to establish
671685 fi
672686
673687 sleep 5
0 commit comments