Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fail the app when binding to a port fails #218

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

laduke
Copy link
Contributor

@laduke laduke commented Mar 28, 2023

tokio is was eating the panics and continuing on
with no socket listening on 53

making tokio crash would take a bunch of rewrite,
i think, so i moved the bind calls out to a different fn

The error looks like this:

thread 'main' panicked at 'Could not bind TCP port 53. Are you root?', ~/repos/github.com/zerotier/zeronsd/src/server.rs:31:23
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

Copy link
Contributor

@erikh erikh left a comment

Choose a reason for hiding this comment

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

These are suggestions I have for the betterment of the user experience, I hope you agree they are worthwhile changes.

Thanks!

let (tcp_socket, udp_socket) = match Server::bind(ip.ip()).await {
Ok(x) => x,
Err(_) => {
panic!("Could not bind port");
Copy link
Contributor

Choose a reason for hiding this comment

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

might be better to change the sig of the return value to return Result<Vec<_>, anyhow::Error> so the original error doesn't get swallowed.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Took a stab at that but then I'd have to change the signature Service::new and then of every test, so...
People running zeronsd tests can figure it out :)

Copy link
Contributor

Choose a reason for hiding this comment

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

I'm not sure that's the best way, but I won't argue with you. :P

src/server.rs Outdated Show resolved Hide resolved
@laduke
Copy link
Contributor Author

laduke commented Mar 28, 2023

Thanks. I couldn't get that to work for some reason and you motivated me to fix it.

Now it makes errors that look like this:

Error: Failed to bind TCP port 53

Caused by:
    Permission denied (os error 13)
Error: Failed to bind UDP port 53

Caused by:
    Address already in use (os error 48)

tokio is was eating the panics and continuing on
with no socket listening on 53

making tokio crash would take a bunch of rewrite
i think, so i moved the `bind` calls out to a different,
non-async fn
@erikh
Copy link
Contributor

erikh commented Mar 29, 2023

Glad to be of help! I hadn't used with_context() before. Neat call!

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.

2 participants