Fable: Unhandled Exception: System.Net.Sockets.SocketException: Address already in use

Created on 12 Apr 2017  路  10Comments  路  Source: fable-compiler/Fable

When following the directions from the blog post, if I run dotnet fable npm-run build and then as soon as it finishes I run dotnet fable npm-run build again, I get this error:

Unhandled Exception: System.Net.Sockets.SocketException: Address already in use
   at System.Net.Sockets.Socket.DoBind(EndPoint endPointSnapshot, SocketAddress socketAddress)
   at System.Net.Sockets.Socket.Bind(EndPoint localEP)
   at System.Net.Sockets.TcpListener.Start(Int32 backlog)
   at Fable.Tools.Server.start(Int32 port, Int32 timeout, FSharpFunc`2 onMessage)
   at Fable.Tools.Main.main(String[] argv)

Even if I wait for a bit and try again, it keeps giving the same error.

The only way to fix it is to wait for ~15-30 seconds, and then it works again.

  • Operating system: Debian GNU/Linux Testing (64-bit)

Most helpful comment

I did a bit of digging into this.

Found the following comment which explains what's going on here for linux and lists some workarounds. https://github.com/dotnet/corefx/issues/9780#issuecomment-232103001

Looks like to take advantage of SO_REUSEADDR we'd just need to add server.Server.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.ReuseAddress, true) before starting the server https://github.com/fable-compiler/Fable/blob/d86c556e77ec7dc8af4f50390b17c7cc59c14e98/src/dotnet/Fable.Tools/Server.fs#L67-L68

I don't have a linux vm handy at the moment to verify though. @Pauan @MangelMaxime can one of you maybe validate?

All 10 comments

Just adding the link with #771

@MangelMaxime Oh, I didn't see that issue. I searched for address but it didn't show up in the Issues list.

For the record, it happens even after I see the Closing server... message, and I'm using fable-loader@^1.0.0-narumi-908

@Pauan Yes I have the same problem under linux.

Just didn't find the time to investigate it.
As a work around, you can start fable with dotnet fable start and then run webpack or webpack-dev-server. Like that you only need to kill webpack and fable will still be running.

I did a bit of digging into this.

Found the following comment which explains what's going on here for linux and lists some workarounds. https://github.com/dotnet/corefx/issues/9780#issuecomment-232103001

Looks like to take advantage of SO_REUSEADDR we'd just need to add server.Server.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.ReuseAddress, true) before starting the server https://github.com/fable-compiler/Fable/blob/d86c556e77ec7dc8af4f50390b17c7cc59c14e98/src/dotnet/Fable.Tools/Server.fs#L67-L68

I don't have a linux vm handy at the moment to verify though. @Pauan @MangelMaxime can one of you maybe validate?

Thanks a lot for investigating this, @johlrich! Actually, I tried on a mac and had a similar issue. I'll implement your suggestion and release a new version so everybody can easily try it out :+1:

I have published dotnet-fable 1.0.0-narumi-909 (it may still a few minutes until Nuget indexes it) with the change proposed by @johlrich. Could you please give it a try and reopen the issue if doesn't work for you yet?

Oh great thanks @johlrich

Edit: @alfonsogarciacaro Sure, I will keep you inform.

@alfonsogarciacaro @johlrich I just tried 1.0.0-narumi-909 and it works! :heart:

Awesome, thanks @Pauan for the confirmation and thanks a lot @johlrich for the fix! I think in the current version you still see the Closing server... message after the process has finished, but I already fixed that locally and should be present in the next version :+1:

Was this page helpful?
0 / 5 - 0 ratings

Related issues

alfonsogarciacaro picture alfonsogarciacaro  路  3Comments

funlambda picture funlambda  路  4Comments

krauthaufen picture krauthaufen  路  3Comments

SirUppyPancakes picture SirUppyPancakes  路  3Comments

et1975 picture et1975  路  3Comments