Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
1 task done
zkeyg opened this issue May 21, 2025 · 2 comments
Assignees
Labels
enhancement New feature or request

Comments

@zkeyg
Copy link

zkeyg commented May 21, 2025

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
@urfeex
Copy link
Member

urfeex commented May 22, 2025

I have experienced this problem in the past. On some systems I was able to reproduce this issue somewhat reliable, on others not at all, so I never followed it too much. Though, when writing this I remember, that we even have a sleep in our CI between running the examples because of exactly that reason...

Setting SO_REUSEADDR seems like a reasonable approach to this problem, thank you for pointing us into that direction!

@urfeex urfeex self-assigned this May 22, 2025
@urfeex urfeex added the enhancement New feature or request label May 22, 2025
@zkeyg
Copy link
Author

zkeyg commented May 22, 2025

Appreciate it! I tested on my own UR20 but have not tested on other platforms.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants