-
Notifications
You must be signed in to change notification settings - Fork 66
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
startServer: no way to avoid port collision? #50
Comments
If you want to avoid a port collision, you should pass |
It's not documented what that does, but I assume it picks a random free port? In that case, is there a way to find out what it picked? |
It's oddly one of those common knowledge things that has been this way for a long time, but isn't well documented (I think MS documents it in some of their BSD socket stuff, but I don't know much about MS). You can ask what was chosen, but that's not exposed in the APIs here. |
Yeah I had the feeling that's what it does but couldn't find anything explicitly saying so. I guess that means this would also be satisfied by a getPort sort of thing, but it looks like it would involve seeing if snap exports it. In any case I assume this will never happen unless I go make a PR, but it's not a huge problem yet so I'm not motivated either (yet)... so we can leave this as a record for another possible way to solve the problem :) |
A drive-by comment since I'm no longer the maintainer but I do think there should be ekg-snap, ekg-wai, ekg-yesod, etc to make integration for people who are actually using ekg in web servers easier. In those cases ekg-* should probably add framework-specific metrics as well. |
startServer starts a new thread, and if that thread can't get the given port, it throws an exception back to the main process. This means that there seems to be no way to reliably pick the first available port since you can't really guess how long it will be before you get that async exception. In my case it winds up killing an unrelated process.
An easy solution would be to export startServer, then I could catch the bind failure exception synchronously and try another port.
The text was updated successfully, but these errors were encountered: