-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
Display useful suggestions in error message on windows when port reserved? (bind EACCES) #2894
Comments
Oh, and the full stacktrace is here:
|
I'll let the resident Windows Guy take this one 😆 |
'resident Windows Guy'? This affects both SSL & TCP listeners (both use |
Hey, some of us wear the "resident windows guy" badge with honor 😂 I for one, take pride in complying with the Win32 documented API contract to the letter, checking every single return code, using SAL like it's my only method of human-to-human communication, and compiling one off little test programs with (I had way too much fun writing that) |
I have started a branch for this issue, hope to finish this weekend. I assume you've noticed that Puma builds with the Ruby mswin build? JFYI, I used both the original IBM & Compaq PC's. I'm pretty good with MSFT Office, so I'll always have a Windows PC, but as to coding, it's just another OS. Most of my OSS work is in WSL2/Ubuntu. |
Heh, no worries, just poking fun 😉😉 |
Is your feature request related to a problem? Please describe.
A problem I encounter all the time on windows is that Hyper-V (or someone else) will reserve a port like port 3000. It's not in use, it's reserved. If I try to start up rails with the default port, then everything will crash when puma fails to create a
TCPServer
on that port. It's not obvious from the documentation thatTCPServer.new
can raise (though it does), so puma does not handle this.I'm used to diagnosing this, you need to check the reserved ports with
netsh interface ipv4 show excludedportrange protocol=tcp
, but this is quite surprising if you have no idea what's going on. If you check the ports in use, you will see that port is not in use! The only fix is to reboot, something you may end up doing in the meantime, and likely you won't know why it worked.Because puma does not handle this, rails (or whatever app you're using) simply crashes with a stacktrace, and the message
C:/Ruby31-x64/lib/ruby/gems/3.1.0/gems/puma-5.6.4/lib/puma/binder.rb:341:in
initialize': Permission denied - bind(2) for "::1" port 3000 (Errno::EACCES)`.Describe the solution you'd like
One useful option might be to detect when (on Windows) the exception is
EACCES
instead ofEADDRINUSE
, and dump a useful error to the screen before reraising. The message could be something like:If in an interactive session, this wouldn't change any behavior, since it would still run through the current exception handling. In any other context, it could cause issues, so I do not expect this to be the solution you adopt :) You could check to see if puma is running in an interactive context too.
Describe alternatives you've considered
One option is puma could run the command in a subshell and parse the results to see if it's in the range before providing a message. That sounds like extra complexity.
Additional context
I suspect many other kernel mode things could allocate/reserve the port, but Hyper-V is certainly the thing that I most commonly encounter. Those would still probably show up in the
excludedportrange
, but I have no clue if they would also choose a random set of ports on each boot. I don't know why Hyper-V does this specifically... it could be an anti-anti-debugging/anti-sandbox-evasion feature?The text was updated successfully, but these errors were encountered: