[PR #2260] [MERGED] NextRandomUdpSocket: fall back to port 0 if no port was found #2910

Closed
opened 2026-03-16 11:14:58 +03:00 by kerem · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/hickory-dns/hickory-dns/pull/2260
Author: @Luap99
Created: 6/26/2024
Status: Merged
Merged: 7/1/2024
Merged by: @djc

Base: mainHead: udp-random


📝 Commits (1)

  • ba873c0 NextRandomUdpSocket: fall back to port 0 if no port was found

📊 Changes

1 file changed (+9 additions, -14 deletions)

View changed files

📝 crates/proto/src/udp/udp_stream.rs (+9 -14)

📄 Description

Trying random ports over and over is not useful, in case where you run on a system that has all or allmost all udp ports used up this logic will not find a free port and it just keep slooping over and over.

As an example I tried to use it with all udp ports 1024-65535 bound and then did an example dig lookup against the server wich tried to forward the request. Dig tried 3 times and I recorded a total of over 220 thousand bind syscalls and it just run into the timout.

With this patch it still tries 10 times random but then directly falls back to letting the OS assign us a free one. This works great if there is still a free port. If there are none then it returns the EADDRINUSE from the port 0 bind call back to the caller. This caused the hickory_resolver to actually switch over to tcp where I had many free ports so the request worked.

Therefore I think this makes more sense to just keep trying.

Fixes #2230


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/hickory-dns/hickory-dns/pull/2260 **Author:** [@Luap99](https://github.com/Luap99) **Created:** 6/26/2024 **Status:** ✅ Merged **Merged:** 7/1/2024 **Merged by:** [@djc](https://github.com/djc) **Base:** `main` ← **Head:** `udp-random` --- ### 📝 Commits (1) - [`ba873c0`](https://github.com/hickory-dns/hickory-dns/commit/ba873c0489e146a6061dd9307f2fe312dcdfb244) NextRandomUdpSocket: fall back to port 0 if no port was found ### 📊 Changes **1 file changed** (+9 additions, -14 deletions) <details> <summary>View changed files</summary> 📝 `crates/proto/src/udp/udp_stream.rs` (+9 -14) </details> ### 📄 Description Trying random ports over and over is not useful, in case where you run on a system that has all or allmost all udp ports used up this logic will not find a free port and it just keep slooping over and over. As an example I tried to use it with all udp ports 1024-65535 bound and then did an example dig lookup against the server wich tried to forward the request. Dig tried 3 times and I recorded a total of over 220 thousand bind syscalls and it just run into the timout. With this patch it still tries 10 times random but then directly falls back to letting the OS assign us a free one. This works great if there is still a free port. If there are none then it returns the EADDRINUSE from the port 0 bind call back to the caller. This caused the hickory_resolver to actually switch over to tcp where I had many free ports so the request worked. Therefore I think this makes more sense to just keep trying. Fixes #2230 --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
kerem 2026-03-16 11:14:58 +03:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/hickory-dns#2910
No description provided.