Skip to content

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 3 times, most recently from d4745f9 to 1ad0a47 Compare October 17, 2022 03:13
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
@rbjorklin rbjorklin force-pushed the allow-specifying-bind-addr branch 2 times, most recently from bdfdf4f to f8a722a Compare December 6, 2025 20:19
@rbjorklin rbjorklin force-pushed the allow-specifying-bind-addr branch from f8a722a to abbb7fe Compare December 6, 2025 20:20
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