zerotier / ZeroTierOne

A Smart Ethernet Switch for Earth
https://zerotier.com
Other
14.57k stars 1.71k forks source link

Management port closure is not handled correctly #2407

Open starlightcrafted opened 3 days ago

starlightcrafted commented 3 days ago

Before filing a Bug Report

Using these will ensure you get quicker support, and make this space available for code-related issues. Thank you!

If you are having a connection issue, it's much easier to diagnose through the discussion forum or the ticket system.

If you still want to file a Bug Report

Please let us know

What you expect to be happening.

ZeroTier Client shuts down and management ports are cleared

What is actually happening?

ZeroTier Client does not seem to set SO_REUSEADDR, or there is something else not releasing the port, so the management port cannot be immediately reused if the management port receives HTTP calls right before restarting or if a HTTP client keeps the connection open while it is restarting.

On restart, the ZeroTier Client starts emitting the error /usr/sbin/zerotier-one: fatal error: cannot bind to local control interface port 9993 and fails to restart until the time defined at /proc/sys/net/ipv4/tcp_tw_recycle has passed.

Any steps to reproduce the error.

Run the below bash script in one window. Restart ZeroTier Client in another.

This is a simple script to simulate the ZeroTier Client restarting while a there is still a connection to the management port.

#!/bin/bash

while true
do
telnet localhost 9993
done

Using some debugging tools like ss you can now see there are left over TCP-WAIT connections.

ss state time-wait sport = 9993

Which can then be killed using

ss state time-wait sport = 9993 -K

A quick fix in case someone else experiences this is to just add the following to /etc/systemd/system/zerotier-one.service.d/kill.conf

[Service]
ExecStartPre=/usr/bin/ss state time-wait sport = 9993 -K

Any relevant console output or screenshots.

What operating system and ZeroTier version. Please try the latest ZeroTier release.

Ubuntu 24.04 ZeroTier 1.14.0