Skip to content

Commit 030aa03

Browse files
committed
Fix crash: skip HolePunch bind when WireGuard owns UDP port
WireGuard's embeddable library binds UDP 51940 for its own socket. HolePunchService also tried to bind the same port, causing "bind: Address already in use" crash on every restart (1226 restarts). Now skip standalone HolePunch when WG is active — WG keepalive handles NAT traversal on the shared port.
1 parent 53f0f0d commit 030aa03

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

projects/LemonadeNexus/src/main.cpp

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -635,8 +635,16 @@ int main(int argc, char* argv[]) {
635635
// ========================================================================
636636
// UDP Hole Punch
637637
// ========================================================================
638-
nexus::network::HolePunchService hole_punch{coordinator.io_context(), udp_port};
639-
hole_punch.start();
638+
// HolePunch shares the UDP port with WireGuard. If WG is active on the
639+
// same port, WG handles the UDP socket — skip the standalone HolePunch bind.
640+
std::optional<nexus::network::HolePunchService> hole_punch;
641+
if (tunnel_bind_ip.empty()) {
642+
// No WG interface — start standalone HolePunch on the UDP port
643+
hole_punch.emplace(coordinator.io_context(), udp_port);
644+
hole_punch->start();
645+
} else {
646+
spdlog::info("HolePunch: WireGuard active on :{} — hole punch via WG keepalive", udp_port);
647+
}
640648

641649
// ========================================================================
642650
// Run -- blocks until SIGINT/SIGTERM
@@ -763,7 +771,7 @@ int main(int argc, char* argv[]) {
763771
if (acme_renewal_thread.joinable()) {
764772
acme_renewal_thread.join();
765773
}
766-
hole_punch.stop();
774+
if (hole_punch) hole_punch->stop();
767775
wireguard_service.stop();
768776
if (private_http_server) {
769777
private_http_server->stop();

0 commit comments

Comments
 (0)