Skip to content

Add option to allow specifying address to bind to #51

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

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

rbjorklin
Copy link

@rbjorklin rbjorklin commented Oct 12, 2022

I have attempted to maintain full backwards compatibility while also allowing one to specify the bind address with --listen-prometheus-addr which otherwise just defaults to 0.0.0.0.

Unfortunately something in conduit_lwt_server throws Uncaught exception accepting connection: Unix.Unix_error(Unix.EINVAL, "accept", "") when trying to use this no matter what address is being used.

I'm hoping the maintainers of this repo can shed some light on what might be going on otherwise I will open an issue against conduit as I think the implementation in this PR should work.

EDIT: I just came across this bit regarding the use of cloexec, thoughts?

@talex5
Copy link
Contributor

talex5 commented Oct 14, 2022

Well, you're creating sockaddr but then throwing the address away and just keeping the domain. You probably want to bind somewhere.

@rbjorklin rbjorklin force-pushed the allow-specifying-bind-addr branch from 305bdbb to 0cf500c Compare October 15, 2022 04:06
@rbjorklin
Copy link
Author

Beej's Guide to the rescue. The PR works now 😃

@rbjorklin rbjorklin force-pushed the allow-specifying-bind-addr branch 2 times, most recently from 04f9d2a to d4745f9 Compare October 15, 2022 04:56
Copy link
Contributor

@talex5 talex5 left a comment

Choose a reason for hiding this comment

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

It might be better to have a single option e.g. --listen-prometheus=127.0.0.1:9090. At the moment, it's unclear what should happen if you give e.g. an address and no port. Also, since we have defaults for both host and port, we could also allow just --listen-prometheus to turn it on without specifying either value.

Will need some compatibility handling for the old port option (and an error if you give both).

let () = Lwt_unix.setsockopt socket SO_REUSEADDR true in
let mode = `TCP (`Socket socket) in
let callback = Server.callback in
let () = Lwt.async (fun () -> Lwt_unix.bind socket addrinfo.ai_addr) in
Copy link
Contributor

Choose a reason for hiding this comment

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

This isn't going to be reliable. It should be done inside thread, not racing with it.

Copy link
Author

Choose a reason for hiding this comment

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

Made the port binding synchronous, this should be a lot more reliable.

@rbjorklin rbjorklin force-pushed the allow-specifying-bind-addr branch from ad4b57a to 9a048dc Compare November 22, 2022 06:42
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