-
Notifications
You must be signed in to change notification settings - Fork 95
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
Port is being re-bound under windows 10 (native shell) preventing portfinder logic from working #39
Comments
howdy @dharmax - can you provide more info? What do you mean by
do you mean If you give me some more detail I'm more than glad to help work through this with you. Thanks! |
Sorry, 8000, yeah. |
Thanks @dharmax for confirming - which version of portfinder are you running? If your running the latest version, do mind setting this env var before you start your process:
e.g.,:
If you have a chance, paste that into a gist and drop me the link - I'll figure it out from there. Thanks again |
@eriktrom @indexzero I also have the same probelm on Windows 10 (Version 10.0.10586) development machine, but works well on Linux machines. Seems windows 10 is allowing http.createServer(express()) and net.createServer listening on the same port with the same host (though the net server isn't working). The screenshots are here: Here are the steps to reproduce:
Here are my packages:
Since many people are using Node express http server, and net server is failing, so maybe we need to use http server to test a port's availability? |
howdy @noahzark - thanks for the detailed report Couple of quick questions will help me a bunch:
perhaps very important note - node 6 is about to become LTS so @noahzark verifying u can't bind to EDIT: Does this bind twice as well? (if no python, no worries): python -m SimpleHTTPServer 10004
python -m SimpleHTTPServer 10004 Background/Diagnosis: The output that u pasted says there are 3 servers running on port Thanks again for finding this and the great detail in ur bug report - ur awesome :) (fyi @stefanpenner - ping me if u see this in ember-cli/angular-cli 👍) |
@eriktrom Thank you so much for your response, it really helps a lot.
So, in my previous projects I used socket to find available ports, it used to be working on Windows 7, |
- Binding to 0.0.0.0 was used in an earlier iteration of the port finding logic. That logic has since been replaced by explicitly testing the OS's network interfaces and is thus no longer of use. fixes #39
@noahzark - hey I really appreciate the info u provided. I pushed what I believe should fix the issue to 6ee0553 - do u mind merging or installing that sha directly into ur setup to test it out tl;dr - we no need longer look at |
@eriktrom Hmm... Seems this fix still doesn't work due to the Windows allows to bind several times using the same port & host When I tried to remove the options.host argument and changed that line to So I'm wondering if we can ignore the interfaces and just bind to the port on Windows ( Just like the elder portfinder version works well on the M$ platform |
I can confirm that portfinder doesn't work on Windows 10 as expected, always indicating a busy port as free. The entire module purpose is compromised. I think this is a breaking bug which must be fixed ASAP. |
@noahzark - just to clarify this sentence in context of the way the old portfinder worked
In older versions, if you started a python server on port X and then ask portfinder to find an open port, starting with X, it would happily say 'yes port X is open' when the truth is 'Yes port X is open, but on a different interface (and therefore w/ a different ip address) than you may have expected'. Sorry @noahzark - I don't follow this sentence:
Can you re-phrase if u get a chance? @artch - yes I agree - the problem is that I'm not exactly sure how to handle this issue yet. Last week I read through net, http and dns modules inside the node source code, including some of the libuv code - and scanned through the issue list as well - the issue you mention specifically
is certainly a problem If there is a way we can think of to hack around the fact that windows will NOT bind (as @noahzark mentioned in any language) to busy ports as though they are free, I'm all ears. I honestly thought the removing the I suppose one hack that would work, while a bit crazy, but would work - would be to start the server that checks each port, make a request, and if the handler gets hit, pipe I'll write that code but I'd love to hear any feedback for suggestions for another implementation thats not so hacky if someone has any thoughts. To be clear the old way that port finder worked did not take into account this binding to multiple interfaces(or hosts within a single interface) and thus any port it found was literally dumb luck. #13 has the details on that. Thanks for your help all and @artch - we'll get this fixed up - sorry I didn't respond earlier this week - I am just not yet sure of the best answer. I do realize the urgency. |
This sounds like pretty reliable approach to me. |
@artch - thanks for the feedback 👍 One question I have is: When windows 10 allows re-binding to a host+port, like in the python simple http server example, does the second 'bind' take precedence over the first? Regardless - on friday night I'll have access to a few machines that can run my Parallels install of Windows 10 and I'll make these changes and test out this monkey business thats going on. My own macbook pro 13 inch w/ 8gb of ram and limited ssd drive space hardly runs it. Boo.) Till then, worth noting you can pass a host and port explicitly - although not sure that'll give you 'the truth' ATM on windows 10 - unless your sure host+port are open, just fyi. |
- Windows 10 native shell(#39) was rebinding to already bound ports. We now send a message from a socket client -> server -> client to ensure a host + port are actually open - Windows 10 bash shell falls back to using 0.0.0.0 as the only host we check in order to prevent throwing a syscall error as being tracked here: microsoft/WSL#468 fixes: #39 closes: #41 fixes: ember-cli/ember-cli#6338
@artch @noahzark - fwiw - I shipped the proposed fix for windows native shell and it broke on computers with bluetooth enabled. I currently don't have another way to hack around the way windows 10 is allowing u to bind to a port more than once. If u guys come across such knowledge, drop me a note here. |
Get this issue after using the windows 10 branch. I fixed the issue with It calling the |
@khrome83 - yeah sorry about that - so to clarify - there are 2 windows 10 issues - one with the native shell and one with the bash shell - if you hit I had a hack in place for the windows 10 bash shell that did work - which I may add back in although I'd rather wait for windows bash shell to add networking to their stack - but let me know ur opinion and if u think we should add back in that hack |
@eriktrom In the short term, the hack would be ideal. Even if it's just on a separate branch. I am on the Insiders ring, and it will still take months to make it too me on the Slow Ring given the release path before, and the users not on Insiders ring won't receive the update until the Windows 10 Creative update launch I assume. Are there any downsides on leaving the hack in? |
@khrome83 - actually its on master ATM - do u mind working off that - let me know if u hit any issues too - if not I'll cut a release with master as is I merged this in a couple weeks back - haven't released to npm though (b/c I haven't fully had the time to battle test it) - #46 downsides to leaving the hack are minimal - there are a number of repos that have this hack |
@khrome83 - hows master working out - I don't launch windows much - let me know if u do use it - thanks a bunch |
Going to give this a shot and see if it resolves the issue. Sorry @eriktrom I have not had a chance to look into it. Was working on my MacBook. Reinstalling the repo on the SurfaceBook to see if master resolves the issue. |
ur awesome thanks again if things are not working - u can set the env var it works in parallels, never tried a real windows machine, so really, thanks |
It got me past my pervious error. Now I am getting a different issue.
Guessing this is a webpack problem though. Posting here just in case you think otherwise. |
Yeah - looks like webpack - maybe fix it for them - here is how yarn package manager fixed their issue https://github.com/yarnpkg/yarn/pull/772/files - the code for portfinder (bottom of portfinder js, from #46 is very similar, easy pickins i'd say :) |
also - thanks - i'll make the move in the morning to cut a release now that I have double verification that it works - if something changes and u find a bug, drop me a HALP comment so I dont release a bad version :) |
I'm having this problem (portfinder not working as expected on Win10) and found this issue, but, after reading the entire discussion I'm not sure if it was fixed or not. |
Sorry it's not fixed yet. Look for it soon though Work around in the meantime is pass a port that u know is open for sure. |
This package works in Windows 10: https://www.npmjs.com/package/get-port The API is very similar. |
@Leftium - thanks for the link I don't believe this is an issue any longer. IIRC (more than a year ago) this issue only happened when using the developer build of windows 10 and checking the box that said something like 'allow port rebinding' within the developer experiments settings (same settings panel where you turn on bash for windows) closing, thanks again for the alternate package, perhaps I can find some answers for things I never fully understood in this package (os level stuff in node -> libuv intricacies) |
Oh, I think I misinterpreted this issue. If my problem is a different issue, I can open a new issue. If another instance of my app was already using port 80, portfinder used to give the 2nd instance of my app port 81. Now it just throws this error (which defeats the purpose of using portfinder):
|
However, this simple code does work:
export function findFreePort() { return new Promise((resolve, reject) => { var server = createServer() , port = 0 server.on("listening", function () { port = server.address().port server.close() }) server.on("close", function () { resolve(port) }) server.on('error', function (err) { reject(err) }) server.listen(0, '127.0.0.1') }) }
The text was updated successfully, but these errors were encountered: