TCP Connection Stops after 180 Seconds

Ubuntu Version: 24.04

Problem Description:
Hi, I am new to the Ubuntu forums, but I am looking for some technical expertise on a problem I’ve been facing for a few days. I’m running a ROS2 node from a python script on a Rapsberry Pi 4 running Ubuntu. The purpose of the script is to communicate to a teensy microcontroller via TCP over ethernet. I have successfully done this, however I am facing a weird problem. Once I get a successful TCP connection, it stays connected for 180 seconds, then disconnects until the OS relinquishes the socket. The purpose of this microcontroller is for timing based controls, so a several second delay for reconnecting will not be usable.

I am posting on an Ubuntu forum not to hope someone can fix everything, but to see if this is possibly something to do with the OS, as I have spent a large amount of time attempting to fix the Teensy code and the python code.

Relevant System Information: Raspberry Pi 4, Teensy 4.1 native ethernet
Both devices have and keep a static IP address, and the Teensy keeps a static MAC address.

Symptoms:
During the disconnect, the raspberry pi thinks that it is still sending messages over the socket, but they are not being received by the Teensy. The Teensy stops being able to read any messages from pi after the 180 seconds have passed.

ARP ack is still coming from the Teensy.

A heartbeat message is sent every second to and from both devices, ensuring that a timeout issue is not occurring.

Once the TCP is broken, rebooting the Teensy reconnects the two. Also, unplugging and replugging the ethernet reconnects them.

If I wait a few more minutes, the two reconnect, as long as both of the scripts are still looking to start a new TCP connection.

Future
Please let me know if there is something I can run in the terminal or some program to figure out the root of the cause. This issue is very reproducible, always occurring 180 seconds after the connection begins.

Thanks in advance for any help!

Is that connection actually usable during those 180 seconds?

Or, when attempting to use it, during those first 180 seconds, do you get an error message/code reported?

If you open a terminal and enter the command

tail -f /var/log/syslog

do you see any event(s) reported at about the time when it times out?

During the time it is connected, the TCP communication is fully functional with no lags or any problems. I get some errors by the system’s network manager as popups during the connection, but when they occur I have no break in connection. Here is the message:
"Connection Failed

Activation of network connection failed".

Here are the logs from tail:

2025-10-03T10:16:40.581697-04:00 ubuntu NetworkManager[1207]: <warn>  [1759501000.5733] device (eth0): Activation: failed for connection 'netplan-eth0'
2025-10-03T10:16:40.585412-04:00 ubuntu avahi-daemon[1090]: Withdrawing address record for fe80::da3a:ddff:fef8:f756 on eth0.
2025-10-03T10:16:40.587271-04:00 ubuntu NetworkManager[1207]: <info>  [1759501000.5751] device (eth0): state change: failed -> disconnected (reason 'none', sys-iface-state: 'managed')
2025-10-03T10:16:40.588137-04:00 ubuntu avahi-daemon[1090]: Leaving mDNS multicast group on interface eth0.IPv6 with address fe80::da3a:ddff:fef8:f756.
2025-10-03T10:16:40.590119-04:00 ubuntu avahi-daemon[1090]: Interface eth0.IPv6 no longer relevant for mDNS.
2025-10-03T10:16:40.591131-04:00 ubuntu NetworkManager[1207]: <info>  [1759501000.5879] dhcp4 (eth0): canceled DHCP transaction
2025-10-03T10:16:40.593370-04:00 ubuntu NetworkManager[1207]: <info>  [1759501000.5881] dhcp4 (eth0): activation: beginning transaction (timeout in 45 seconds)
2025-10-03T10:16:40.595545-04:00 ubuntu NetworkManager[1207]: <info>  [1759501000.5884] dhcp4 (eth0): state changed no lease
2025-10-03T10:16:40.597229-04:00 ubuntu avahi-daemon[1090]: Withdrawing address record for 192.168.10.101 on eth0.
2025-10-03T10:16:40.598651-04:00 ubuntu avahi-daemon[1090]: Leaving mDNS multicast group on interface eth0.IPv4 with address 192.168.10.101.
2025-10-03T10:16:40.599060-04:00 ubuntu avahi-daemon[1090]: Interface eth0.IPv4 no longer relevant for mDNS.
2025-10-03T10:16:40.608603-04:00 ubuntu NetworkManager[1207]: <info>  [1759501000.6075] policy: auto-activating connection 'netplan-eth0' (626dd384-8b3d-3690-9511-192b2c79b3fd)
2025-10-03T10:16:40.611593-04:00 ubuntu NetworkManager[1207]: <info>  [1759501000.6099] device (eth0): Activation: starting connection 'netplan-eth0' (626dd384-8b3d-3690-9511-192b2c79b3fd)
2025-10-03T10:16:40.611997-04:00 ubuntu NetworkManager[1207]: <info>  [1759501000.6105] device (eth0): state change: disconnected -> prepare (reason 'none', sys-iface-state: 'managed')
2025-10-03T10:16:40.614511-04:00 ubuntu NetworkManager[1207]: <info>  [1759501000.6140] device (eth0): state change: prepare -> config (reason 'none', sys-iface-state: 'managed')
2025-10-03T10:16:40.620302-04:00 ubuntu NetworkManager[1207]: <info>  [1759501000.6175] device (eth0): state change: config -> ip-config (reason 'none', sys-iface-state: 'managed')
2025-10-03T10:16:40.622444-04:00 ubuntu NetworkManager[1207]: <info>  [1759501000.6191] dhcp4 (eth0): activation: beginning transaction (timeout in 45 seconds)
2025-10-03T10:16:40.628481-04:00 ubuntu avahi-daemon[1090]: Joining mDNS multicast group on interface eth0.IPv6 with address fe80::da3a:ddff:fef8:f756.
2025-10-03T10:16:40.629276-04:00 ubuntu avahi-daemon[1090]: New relevant interface eth0.IPv6 for mDNS.
2025-10-03T10:16:40.629670-04:00 ubuntu avahi-daemon[1090]: Registering new address record for fe80::da3a:ddff:fef8:f756 on eth0.*.
2025-10-03T10:16:40.798239-04:00 ubuntu avahi-daemon[1090]: Joining mDNS multicast group on interface eth0.IPv4 with address 192.168.10.101.
2025-10-03T10:16:40.798829-04:00 ubuntu avahi-daemon[1090]: New relevant interface eth0.IPv4 for mDNS.
2025-10-03T10:16:40.799155-04:00 ubuntu avahi-daemon[1090]: Registering new address record for 192.168.10.101 on eth0.IPv4.
2025-10-03T10:17:01.052643-04:00 ubuntu CRON[30209]: (root) CMD (cd / && run-parts --report /etc/cron.hourly)
2025-10-03T10:17:25.565892-04:00 ubuntu NetworkManager[1207]: <info>  [1759501045.5628] device (eth0): state change: ip-config -> failed (reason 'ip-config-unavailable', sys-iface-state: 'managed')
2025-10-03T10:17:25.573613-04:00 ubuntu NetworkManager[1207]: <warn>  [1759501045.5657] device (eth0): Activation: failed for connection 'netplan-eth0'
2025-10-03T10:17:25.579044-04:00 ubuntu avahi-daemon[1090]: Withdrawing address record for fe80::da3a:ddff:fef8:f756 on eth0.
2025-10-03T10:17:25.580601-04:00 ubuntu NetworkManager[1207]: <info>  [1759501045.5675] device (eth0): state change: failed -> disconnected (reason 'none', sys-iface-state: 'managed')
2025-10-03T10:17:25.581521-04:00 ubuntu avahi-daemon[1090]: Leaving mDNS multicast group on interface eth0.IPv6 with address fe80::da3a:ddff:fef8:f756.
2025-10-03T10:17:25.581864-04:00 ubuntu avahi-daemon[1090]: Interface eth0.IPv6 no longer relevant for mDNS.
2025-10-03T10:17:25.585047-04:00 ubuntu NetworkManager[1207]: <info>  [1759501045.5845] dhcp4 (eth0): canceled DHCP transaction
2025-10-03T10:17:25.585690-04:00 ubuntu NetworkManager[1207]: <info>  [1759501045.5847] dhcp4 (eth0): activation: beginning transaction (timeout in 45 seconds)
2025-10-03T10:17:25.586068-04:00 ubuntu NetworkManager[1207]: <info>  [1759501045.5849] dhcp4 (eth0): state changed no lease
2025-10-03T10:17:25.588485-04:00 ubuntu avahi-daemon[1090]: Withdrawing address record for 192.168.10.101 on eth0.
2025-10-03T10:17:25.589154-04:00 ubuntu avahi-daemon[1090]: Leaving mDNS multicast group on interface eth0.IPv4 with address 192.168.10.101.
2025-10-03T10:17:25.592446-04:00 ubuntu avahi-daemon[1090]: Interface eth0.IPv4 no longer relevant for mDNS.
2025-10-03T10:17:25.606283-04:00 ubuntu NetworkManager[1207]: <info>  [1759501045.6048] policy: auto-activating connection 'netplan-eth0' (626dd384-8b3d-3690-9511-192b2c79b3fd)
2025-10-03T10:17:25.607131-04:00 ubuntu NetworkManager[1207]: <info>  [1759501045.6066] device (eth0): Activation: starting connection 'netplan-eth0' (626dd384-8b3d-3690-9511-192b2c79b3fd)
2025-10-03T10:17:25.608304-04:00 ubuntu NetworkManager[1207]: <info>  [1759501045.6071] device (eth0): state change: disconnected -> prepare (reason 'none', sys-iface-state: 'managed')
2025-10-03T10:17:25.611232-04:00 ubuntu NetworkManager[1207]: <info>  [1759501045.6105] device (eth0): state change: prepare -> config (reason 'none', sys-iface-state: 'managed')
2025-10-03T10:17:25.617733-04:00 ubuntu NetworkManager[1207]: <info>  [1759501045.6142] device (eth0): state change: config -> ip-config (reason 'none', sys-iface-state: 'managed')
2025-10-03T10:17:25.618604-04:00 ubuntu NetworkManager[1207]: <info>  [1759501045.6176] dhcp4 (eth0): activation: beginning transaction (timeout in 45 seconds)
2025-10-03T10:17:25.624187-04:00 ubuntu avahi-daemon[1090]: Joining mDNS multicast group on interface eth0.IPv6 with address fe80::da3a:ddff:fef8:f756.
2025-10-03T10:17:25.624679-04:00 ubuntu avahi-daemon[1090]: New relevant interface eth0.IPv6 for mDNS.
2025-10-03T10:17:25.624945-04:00 ubuntu avahi-daemon[1090]: Registering new address record for fe80::da3a:ddff:fef8:f756 on eth0.*.
2025-10-03T10:17:25.760215-04:00 ubuntu avahi-daemon[1090]: Joining mDNS multicast group on interface eth0.IPv4 with address 192.168.10.101.
2025-10-03T10:17:25.761740-04:00 ubuntu avahi-daemon[1090]: New relevant interface eth0.IPv4 for mDNS.
2025-10-03T10:17:25.762136-04:00 ubuntu avahi-daemon[1090]: Registering new address record for 192.168.10.101 on eth0.IPv4.
2025-10-03T10:18:10.571904-04:00 ubuntu NetworkManager[1207]: <info>  [1759501090.5696] device (eth0): state change: ip-config -> failed (reason 'ip-config-unavailable', sys-iface-state: 'managed')
2025-10-03T10:18:10.578164-04:00 ubuntu NetworkManager[1207]: <warn>  [1759501090.5724] device (eth0): Activation: failed for connection 'netplan-eth0'
2025-10-03T10:18:10.584020-04:00 ubuntu avahi-daemon[1090]: Withdrawing address record for fe80::da3a:ddff:fef8:f756 on eth0.
2025-10-03T10:18:10.586157-04:00 ubuntu NetworkManager[1207]: <info>  [1759501090.5738] device (eth0): state change: failed -> disconnected (reason 'none', sys-iface-state: 'managed')
2025-10-03T10:18:10.586681-04:00 ubuntu avahi-daemon[1090]: Leaving mDNS multicast group on interface eth0.IPv6 with address fe80::da3a:ddff:fef8:f756.
2025-10-03T10:18:10.586994-04:00 ubuntu avahi-daemon[1090]: Interface eth0.IPv6 no longer relevant for mDNS.
2025-10-03T10:18:10.589250-04:00 ubuntu NetworkManager[1207]: <info>  [1759501090.5886] dhcp4 (eth0): canceled DHCP transaction
2025-10-03T10:18:10.590015-04:00 ubuntu NetworkManager[1207]: <info>  [1759501090.5889] dhcp4 (eth0): activation: beginning transaction (timeout in 45 seconds)
2025-10-03T10:18:10.591046-04:00 ubuntu NetworkManager[1207]: <info>  [1759501090.5891] dhcp4 (eth0): state changed no lease
2025-10-03T10:18:10.595302-04:00 ubuntu avahi-daemon[1090]: Withdrawing address record for 192.168.10.101 on eth0.
2025-10-03T10:18:10.595856-04:00 ubuntu avahi-daemon[1090]: Leaving mDNS multicast group on interface eth0.IPv4 with address 192.168.10.101.
2025-10-03T10:18:10.596668-04:00 ubuntu avahi-daemon[1090]: Interface eth0.IPv4 no longer relevant for mDNS.

I’ve kept some extra lines after the connection break happens, but the break in connection creates lines at this time in the logs:
2025-10-03T10:16:40.XXXXX-04:00

Thank you for your response, please let me know if you want to see any other logs from this at the time of disconnect.

What do you get when you enter

netplan get all

Does your context allow you to set a fixed IP address for the device (which would stabilize the situation by avoiding the DHCP timeouts)?

1 Like

Hi, sorry for the late response. I have figured out the problem. It looks like the two network managers in Ubuntu were fighting against each other. I would set the ip for the ethernet port to static, then three minutes later it would be set back to dhcp and reset the ip. I was setting it to a static IP using the network settings gui. However, if I make a netplan yaml config and write in the static ip there, it works as intended. I am not sure why setting the ethernet port to static in settings is not a permanent setting, but this was the solution for me.

1 Like

This topic was automatically closed after 30 days. New replies are no longer allowed.