ekg
ekg copied to clipboard
startServer: no way to avoid port collision?
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.
If you want to avoid a port collision, you should pass 0
.
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 startServer
is hidden on purpose as the user should care/know what web servers is used behind the scenes. I had a long term plan to switching to something more lightweight.
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.