Skip to content

Failed to bind socket for port xxxx to address. Reason: Address already in useRetrying in 1 seconds #328

@zkeyg

Description

@zkeyg

Affected Client Library version(s)

2.0.0

What combination of platform is the Client Library running on.

Linux without realtime patch, Docker, Linux

How did you install the Client Library

Build the library from source

Which robot platform is the library connected to.

Real robot, UR E-series robot

Robot SW / URSim version(s)

polyscope 5.21.x

How are you using the Client Library

Through the robot teach pendant using External Control URCap

Issue details

Summary

[UR_Client_Library:]: Failed to bind socket for port 50002 to address. Reason: Address already in useRetrying in 1 seconds

Issue details

Using UR-ROS2 driver connected to a UR20 robot using external control cap and UR client library. It appears that some times I'm encountering an issue where the TCP server fails to bind to port 50002 with the error Address already in use, even though no active process is using the port (confirmed via lsof -i :50002). I have a short script checking if port is being used or occupied before the driver is launched. Nothing is detected. My suspicion is that the port is likely held in TIME_WAIT state by the OS, causing the bind() call to fail.

Steps to Reproduce

Start the TCP server on port 50002.
Stop the server.
Restart the server quickly (within a few seconds).
Failed to bind socket for port 50002 to address. Reason: Address already in use

Expected Behavior

Actual Behavior

What did you observe? If possible please attach relevant information.

Workaround Suggestion

I am wondering if adding a flag in the TCP bind function will be useful. Ideally, the TCP server should set SO_REUSEADDR before calling bind() to avoid this issue in the future.

err = ::bind(listen_fd_, (struct sockaddr*)&server_addr, sizeof(server_addr));

int opt = 1;
setsockopt(listen_fd_, SOL_SOCKET, SO_REUSEADDR, &opt, sizeof(opt));

Relevant log output

948
2025-05-17T00:11:23.113Z
[ros2-9] [ur_ros2_control_node-1] [WARN] [1747440683.112865892] [UR_Client_Library:]: Failed to bind socket for port 50002 to address. Reason: Address already in useRetrying in 1 seconds
949
2025-05-17T00:11:24.114Z
[ros2-9] [ur_ros2_control_node-1] [WARN] [1747440684.112995375] [UR_Client_Library:]: Failed to bind socket for port 50002 to address. Reason: Address already in useRetrying in 1 seconds
950
2025-05-17T00:11:25.113Z
[ros2-9] [ur_ros2_control_node-1] [WARN] [1747440685.113131975] [UR_Client_Library:]: Failed to bind socket for port 50002 to address. Reason: Address already in useRetrying in 1 seconds
951
2025-05-17T00:11:26.113Z
[ros2-9] [ur_ros2_control_node-1] [WARN] [1747440686.113244548] [UR_Client_Library:]: Failed to bind socket for port 50002 to address. Reason: Address already in useRetrying in 1 seconds
952
2025-05-17T00:11:27.113Z
[ros2-9] [ur_ros2_control_node-1] [WARN] [1747440687.113353851] [UR_Client_Library:]: Failed to bind socket for port 50002 to address. Reason: Address already in useRetrying in 1 seconds

Accept Public visibility

  • I agree to make this context public

Metadata

Metadata

Assignees

Labels

enhancementNew feature or request

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions