-
Notifications
You must be signed in to change notification settings - Fork 3
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
wait for tcp port available (win32) #2
base: windows
Are you sure you want to change the base?
wait for tcp port available (win32) #2
Conversation
This module follows the normal Mojolicious rules. So tests and documentation are still required. |
Why is this a Windows only feature? I don't see any Windows specific code. It is actually counter to the whole argument for adding the feature in the first place. We could offer it for Windows, macOS and Linux., as a slightly less safe alternative to passing the file descriptor directly to the managed process. |
lib/server-starter.js
Outdated
@@ -90,7 +92,23 @@ class Server extends EventEmitter { | |||
}); | |||
|
|||
// Should be resolved by the "spawn" event, but that is only supported in Node 15+ | |||
return Promise.resolve; | |||
if (process.platform !== 'win32') return Promise.resolve; | |||
return new Promise((resolve) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is no reject handler. What's supposed to happen when it times out?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the caller will do exactly the same (trying to connect), and will fail because the port is not ready.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A promise does not resolve on its own.
lib/server-starter.js
Outdated
(function loop () { | ||
const connection = net.connect(port, resolve); | ||
connection.on('error', err => { | ||
if (err.code === 'ECONNREFUSED') { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And if it's something else?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should resolve the promise. But it actually doesn't, my mistake, see my answer about the logic a few minutes ago
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It should reject the promise, not resolve.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The only thing the loop does is to wait enough time to get the server in a defined (either right or wrong) state. So if there is an error different from ECONNREFUSED there is no need to stay waiting, there is no argue on that.
But I think there is no added value in reject the promise with an error either. This is because you will try to connect by yourself after the launch of the server, and you will be sucesfull or not, and get the right error in any case.
Anyway the promise could be rejected when there is an error detected, the change itself is trivial (although the specific tests are not that easy) but I cannot think of any use case in which this can be beneficial for the user of the module.
lib/server-starter.js
Outdated
const connection = net.connect(port, resolve); | ||
connection.on('error', err => { | ||
if (err.code === 'ECONNREFUSED') { | ||
if (new Date() < timeToStop) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And if it times out we just do nothing?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes the caller will take care, I mean will recive the exact same error
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How does the error reach the caller?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The logic is like:
- wait up to win32Timeout mS, as long as the error you are getting is ECONNREFUSED.
- if you could connect, resolve the promise
- if you get other error, you will not retry
so Ooops, I need to resolve at the end of the anonymous function (or reject, but that will be handled much better by the caller, when it tries to connect)
lib/server-starter.js
Outdated
@@ -64,12 +64,14 @@ class Server extends EventEmitter { | |||
* @param {object} [options] - Optional settings | |||
* @param {boolean} [options.stdout=false] - Forward server output from STDOUT to STDOUT | |||
* @param {boolean} [options.stderr=true] - Forward server output from STDERR to STDERR | |||
* @param {number} [options.win32Timeout=30000] - (Windows only) Max time to wait for server ready, in mS |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As far as i can see there is no reason at all for this to be Windows specific.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It will have no effect on other platforms, at least how is it written.
If you mean to wait for connection ready at the TCP port in all cases, it could be done.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The way it is done now makes little sense. Since the module doesn't become more portable, it just allows someone to use it in a Windows specific way. Instead of enabling one test to run on all platforms.
So, to sum up the requirements. a) The feature needs to work on all platforms, Windows, macOS and Linux. b) There needs to be an additional documentation section explaining how to use the module in a portable (but slightly less safe) way. c) There need to be new tests for success (random and specific port) and failure cases (timeout, failed web app start, connection error other than ECONNREFUSED). |
…tion, as logic turned out to be very different
|
Wait for server ready on windows platforms. This helps to allow a minimal windows platforms support. Related to issue #1