Skip to content
4 changes: 2 additions & 2 deletions registry/coder/modules/kasmvnc/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -292,11 +292,11 @@ VNC_LOG="/tmp/kasmvncserver.log"
printf "🚀 Starting KasmVNC server...\n"

set +e
kasmvncserver -select-de "${DESKTOP_ENVIRONMENT}" -disableBasicAuth > "$VNC_LOG" 2>&1
kasmvncserver -select-de "${DESKTOP_ENVIRONMENT}" -websocketPort "${PORT}" -disableBasicAuth > "$VNC_LOG" 2>&1
RETVAL=$?
set -e

if [[ $RETVAL -ne 0 ]]; then
if [[ $RETVAL -ne 0 ]] && ! curl -s http://127.0.0.1:"${PORT}"/app; then
Copy link

Copilot AI Dec 16, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The curl command is used without checking if it's available. The script already has a download_file function that handles multiple download tools (curl, wget, busybox) as fallbacks. If curl is not available on the system, this health check will fail even if the server started successfully. Consider using a similar fallback pattern or checking for curl availability before using it.

Copilot uses AI. Check for mistakes.
Copy link

Copilot AI Dec 16, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The curl health check is performed immediately after starting the kasmvncserver. There's a potential race condition where the server might need a moment to fully start and bind to the port. If the curl request happens before the server is ready to accept connections, this could result in false negatives. Consider adding a brief sleep or implementing a retry mechanism before checking the health endpoint.

Suggested change
if [[ $RETVAL -ne 0 ]] && ! curl -s http://127.0.0.1:"${PORT}"/app; then
# Retry health check up to 10 times with 1s delay
health_check_with_retries() {
local url=$1
local max_attempts=10
local attempt=1
while (( attempt <= max_attempts )); do
if curl -s "$url" > /dev/null; then
return 0
fi
sleep 1
((attempt++))
done
return 1
}
if [[ $RETVAL -ne 0 ]] && ! health_check_with_retries "http://127.0.0.1:${PORT}/app"; then

Copilot uses AI. Check for mistakes.
echo "ERROR: Failed to start KasmVNC server. Return code: $RETVAL"
if [[ -f "$VNC_LOG" ]]; then
echo "Full logs:"
Expand Down