Skip to content

Fix issue where the second send fails on linux when using UDP.#185

Open
hydra wants to merge 1 commit intojamesmunns:mainfrom
MakerPnP:fix-udp-send-on-linux
Open

Fix issue where the second send fails on linux when using UDP.#185
hydra wants to merge 1 commit intojamesmunns:mainfrom
MakerPnP:fix-udp-send-on-linux

Conversation

@hydra
Copy link
Copy Markdown
Collaborator

@hydra hydra commented Jan 19, 2026

  • this occurs when using a local address for the destination, it may occur on other scenarios too.

This exampled, from tokio-rs/tokio#4996 demonstrates the root cause:

use tokio::net::UdpSocket;

#[tokio::main]
async fn main() {
    let socket =  UdpSocket::bind(("0.0.0.0", 12345)).await.unwrap();
    socket.connect(("127.0.0.1", 1122)).await.unwrap();
    socket.send(b"test 123").await.unwrap();  <-- succeeds
    socket.send(b"test 123").await.unwrap();  <-- fails
}

It was entirely non-obvious why that worked on Windows and on the Linux used by the raspberry Pi was using for testing didn't work on a new linux installation (Bazzite, Fedora 43 20260101 6.17.7-ba22.fc43.x86_64).

* this occurs when using a local address for the destination, it may occur on other scenarios too.

Reference: tokio-rs/tokio#4996
@hydra hydra changed the title Fix issue where the second send fails on linux. Fix issue where the second send fails on linux when using UDP. Jan 19, 2026
Comment on lines +186 to +188
// On Linux, the /SECOND/ `send` will cause a `ConnectionRefused` error when there
// is nothing listening and the source/destination are on the same host.
ErrorKind::ConnectionRefused => {},
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's no guarantee it happens on the second send. See the Tokio issue.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, yes, so perhaps the wording should be:

On Linux, /LATER/ calls to send /MAY/ cause a ConnectionRefused error when there is nothing listening and the source/destination are on the same host.

Thoughts? Improvements?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks good to me. The rewording you proposed looks correct, just needs to be pushed.
Otherwise LGTM.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants