Skip to content
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

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

Closed
Pauan opened this issue Apr 12, 2017 · 10 comments
Closed

Comments

@Pauan
Copy link
Member

Pauan commented Apr 12, 2017

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)
@MangelMaxime
Copy link
Member

Just adding the link with #771

@Pauan
Copy link
Member Author

Pauan commented Apr 12, 2017

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

@Pauan
Copy link
Member Author

Pauan commented Apr 12, 2017

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

@MangelMaxime
Copy link
Member

@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.

@johlrich
Copy link
Contributor

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

let server = new TcpListener(IPAddress.Parse("127.0.0.1"), port)
server.Start()

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

@alfonsogarciacaro
Copy link
Member

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 👍

@alfonsogarciacaro
Copy link
Member

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?

@MangelMaxime
Copy link
Member

MangelMaxime commented Apr 14, 2017

Oh great thanks @johlrich

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

@Pauan
Copy link
Member Author

Pauan commented Apr 15, 2017

@alfonsogarciacaro @johlrich I just tried 1.0.0-narumi-909 and it works! ❤️

@alfonsogarciacaro
Copy link
Member

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 👍

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

No branches or pull requests

4 participants