[Haskell-cafe] Web servers: Running them multiple times in a ghci session

Manuel Gómez targen at gmail.com
Thu Apr 11 08:25:30 CEST 2013


On Thu, Apr 11, 2013 at 12:33 AM, Niklas Hambüchen <mail at nh2.me> wrote:
>
> I'm writing a web server app, which I run in ghci:
>
> :main localhost 8000
>
> Unfortunately, after Ctrl-C and :reload, running it again:
>
> ** Exception: bind: resource busy (Address already in use)
>
> This is pretty annoying, because quitting-and-restarting takes a lot of
> time since I have many dependencies.
>
> How do you deal with this? Can you propose some working code that can be
> wrapped around my main function to make it work?

Just a guess: it probably has to do with `SO_REUSEADDR`; see this old
thread[1] and the comments on `Network.listenOn`[2].  You most likely
want to set the `ReuseAddr` option to 1 on your socket
with`Network.Socket.setSocketOption`.[3]

[1]: <http://www.haskell.org/pipermail/beginners/2010-June/004334.html>
[2]: <http://hackage.haskell.org/packages/archive/network/2.4.1.2/doc/html/Network.html>
[3]: <http://hackage.haskell.org/packages/archive/network/2.4.1.2/doc/html/Network-Socket.html#t:SocketOption>



More information about the Haskell-Cafe mailing list