Skip to content

Fix node hanging indefinitely on TCP connection failures#16

Open
Copilot wants to merge 3 commits intohumble-developfrom
copilot/fix-node-launch-hang-issue
Open

Fix node hanging indefinitely on TCP connection failures#16
Copilot wants to merge 3 commits intohumble-developfrom
copilot/fix-node-launch-hang-issue

Conversation

Copy link

Copilot AI commented Nov 18, 2025

The kuka_kvp_interface node hangs indefinitely when it cannot connect to the KVP Server on the KUKA controller, requiring manual termination. All connection failures produce the same generic error message after Ctrl+C, making debugging difficult.

Changes

Socket timeout

  • Added 5-second timeout to prevent indefinite blocking on connect()

Granular exception handling

  • Replaced bare except: with specific handlers:
    • socket.timeout → Connection timeout error (ID 4)
    • errno.ENETUNREACH → Network unreachable error (ID 5)
    • errno.ECONNREFUSED → Connection refused error (ID 6)
    • Generic OSError → Enhanced network error with details (ID 1)

Error messages

  • Added structured error output with [ERROR] prefix, IP address, and actionable troubleshooting steps for each failure mode

Example

def __init__(self, TCP_IP):
    try:
        client.settimeout(5.0)  # Fail fast instead of hanging
        client.connect((TCP_IP, 7000))
    except socket.timeout:
        self.error_list(4, TCP_IP)
    except OSError as e:
        if e.errno == errno.ENETUNREACH:
            self.error_list(5, TCP_IP)
        elif e.errno == errno.ECONNREFUSED:
            self.error_list(6, TCP_IP)
        else:
            self.error_list(1, TCP_IP, e)

Sample output when KVP Server is not running:

[ERROR] [kuka_kvp_interface]: Connection refused
    KVP Server at 172.31.1.147:7000 refused the connection
    Possible causes:
      - KVP Server is not running on the KR C4 controller
      - Port 7000 is blocked or not configured in NAT settings

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • 192.0.2.1
    • Triggering command: python3 test_connection_errors.py (packet block)
    • Triggering command: python3 test_kuka_errors.py (packet block)
    • Triggering command: python3 demonstration.py (packet block)
  • 203.0.113.1
    • Triggering command: python3 test_connection_errors.py (packet block)
    • Triggering command: python3 test_kuka_errors.py (packet block)

If you need me to access, download, or install something from one of these locations, you can either:

Original prompt

This section details on the original issue you should resolve

<issue_title>Node hangs on launch with no immediate error for network/server connection failures</issue_title>
<issue_description>1. Context

The kuka_kvp_interface node establishes a TCP socket connection to the KVP Server on the KUKA KR C4 controller. This connection is critical for the node's operation.

  1. Problem

When the node is launched under two common failure scenarios, it does not fail immediately or provide a descriptive error. Instead, it hangs indefinitely, forcing the user to terminate it with Ctrl+C. Only after termination is a generic error message shown.

This makes debugging connection issues difficult and inefficient.

Steps to Reproduce:

Scenario 1: Network Unreachable

    Disconnect the host machine from the network or configure it with an incorrect IP address so it cannot reach the robot's subnet.

    Launch the kuka_kvp_interface node.

    Observed Behavior: The launch process hangs. The terminal prints no error or status message. After pressing Ctrl+C, the node exits and prints a generic Network Error (tcp_error).

Scenario 2: KVP Server Not Running

    Ensure the host machine has a valid network connection to the KUKA controller's IP address.

    Ensure the KVP Server application is not running on the KR C4 controller.

    Launch the kuka_kvp_interface node.

    Observed Behavior: The node fails with the observed error.
  1. Desired Behavior

The node should fail fast and provide distinct, immediate, and actionable error messages for different failure modes.

For Scenario 1 (Network Unreachable): The node should immediately print a clear error and exit gracefully.

    Example Error: [ERROR] [kuka_kvp_interface]: Network is unreachable for host <robot_ip>. Please check your computer's network configuration and physical connection.

For Scenario 2 (KVP Server Not Running): The node should immediately print a clear error and exit gracefully.

    Example Error: [ERROR] [kuka_kvp_interface]: Connection was refused by host <robot_ip>. Is the KVP Server application running on the KUKA controller?

The node should not hang or require manual termination in either of these cases.

Acceptance Criteria (Definition of Done)

When launched with a misconfigured network (unreachable host), the node immediately prints a "Network Unreachable" error and exits with a non-zero exit code.

When launched with a valid network connection but no active KVP Server on the robot, the node immediately prints a "Connection Refused" error and exits with a non-zero exit code.

The node must not hang in either of the above scenarios.

If the connection is successful, the node launches and operates normally without any change in behavior.</issue_description>

Comments on the Issue (you are @copilot in this section)


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Copilot AI and others added 2 commits November 18, 2025 09:00
Co-authored-by: codewithlennylen <33583893+codewithlennylen@users.noreply.github.com>
Co-authored-by: codewithlennylen <33583893+codewithlennylen@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix node hanging issue on launch for connection failures Fix node hanging indefinitely on TCP connection failures Nov 18, 2025
@codewithlennylen codewithlennylen marked this pull request as ready for review November 19, 2025 07:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants