Skip to content
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

Errors when using host.docker.internal as a host for a UDP interface #1821

Open
morganwb opened this issue Jan 10, 2025 · 1 comment · May be fixed by #1848
Open

Errors when using host.docker.internal as a host for a UDP interface #1821

morganwb opened this issue Jan 10, 2025 · 1 comment · May be fixed by #1848
Assignees
Labels
bug Something isn't working

Comments

@morganwb
Copy link

morganwb commented Jan 10, 2025

I have been working to set up OpenC3 COSMOS on my local computer and I am struggling to create a UDP interface in either Ruby or Python. I have a simple listener for UDP packets that I run locally and am able to send packets from within a docker container to that listener by using the host.docker.internal hostname. The OpenC3 documentation also states that when setting up a plugin interface, host.docker.internal is a valid host IP for the UDP interface. However, when I create a Python plugin and use the same port that I have tested before, I get the following error:

Microservice DEFAULT__INTERFACE__UDP_INT dying from exception
Traceback (most recent call last):
  File "/openc3/venv/lib/python3.11/site-packages/openc3/microservices/microservice.py", line 51, in class_run
    microservice.run()
  File "/openc3/python/openc3/microservices/interface_microservice.py", line 589, in run
    self.connect()
  File "/openc3/python/openc3/microservices/interface_microservice.py", line 743, in connect
    self.interface.connect()
  File "/openc3/venv/lib/python3.11/site-packages/openc3/interfaces/udp_interface.py", line 132, in connect
    self.write_socket = UdpWriteSocket(
                        ^^^^^^^^^^^^^^^
  File "/openc3/venv/lib/python3.11/site-packages/openc3/io/udp_sockets.py", line 147, in __init__
    super().__init__(
  File "/openc3/venv/lib/python3.11/site-packages/openc3/io/udp_sockets.py", line 56, in __init__
    if UdpReadWriteSocket.multicast(external_address, external_port):
       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/openc3/venv/lib/python3.11/site-packages/openc3/io/udp_sockets.py", line 127, in multicast
    return ipaddress.ip_address(host) in ipaddress.ip_network("224.0.0.0/4")
           ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.11/ipaddress.py", line 54, in ip_address
    raise ValueError(f'{address!r} does not appear to be an IPv4 or IPv6 address')
ValueError: 'host.docker.internal' does not appear to be an IPv4 or IPv6 address

The Ruby UDP interface does not throw the same error, however the command sender does error 30 seconds after sending the command, saying it failed due to not hearing a cmd ack within 30 seconds. I also don't see any packets on my listener from the Ruby interface, either. Is this a problem with me mis-configuring the docker network stack? AFAIK I have not made any changes to the default cosmos-project other than to create my new plugin and define my own base target and interface.

Any idea what the issue here might be? I have been able to get the TCPIP interface working with host.docker.internal but I am struggling with the UDP interfaces. Any advice or further documentation would be very useful. Thank you!

@jmthomas
Copy link
Member

jmthomas commented Jan 15, 2025

I think your python issue is the fact we're using ipaddress.ip_address and passing in a host. The correct way to call this is host_ip = socket.gethostbyname('host.docker.internal') and then use the IP. I'll mark this as a bug and we'll get that corrected.

However, I don't know why the Ruby side would be misbehaving. If you're using docker compose note that it creates a network named after the directory with _default so typically that would be cosmos-project_default when using our cosmos-project. If you run your container with docker run --network cosmos-project_default <CONTAINER> hopefully that will work.

@jmthomas jmthomas added the bug Something isn't working label Jan 15, 2025
@jmthomas jmthomas self-assigned this Jan 18, 2025
@jmthomas jmthomas linked a pull request Jan 18, 2025 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants