-
Notifications
You must be signed in to change notification settings - Fork 29.6k
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
Remove common.PORT usage from parallel
tests
#12473
Conversation
First-time contributor. (Noob level) Thanks for pushing me to get into this! |
Good job @adityaanandmc 👏 |
@adityaanandmc Changes are all good. If you could make sure if the commits follow these guidelines it would be great? |
parallel
tests parallel
tests
@thefourtheye Do the changes look alright ? |
@thefourtheye @cjihrig |
That would probably introduce a race condition. Once you close the server to release the port, something else can claim that port. |
@cjihrig What would be the ideal way to get this done? I was aware of the race condition and hence a little stuck. My commit ( code below ) will fail if the race condition is met.
|
@adityaanandmc wrote
Although the possibility of this happening is less, it is still possible and we cannot avoid it. |
@adityaanandmc what about doing something like this: ...
const server = net.createServer();
server.listen(0);
const port = server.address().port;
const c = net.createConnection(port);
server.close();
... |
@santigimeno Now i feel like a idiot :P Thanks for that!! :D |
@adityaanandmc could you squash the commits into one? Thanks! |
@santigimeno will squash them!! I can't seem to understand the failures. I thought about doing this, but it didn't seem like the right thing to do.
|
@adityaanandmc looking at the changes again it seems that we're trying to |
21c212d
to
582ef62
Compare
@santigimeno @thefourtheye I did that and it passed locally but at times it fails with the following error!
Sorry for flooding you with doubts. Just a lil confused for a first-time contributor on a project of this scale. |
I think the actual error in the output you linked to is this:
That is unrelated, and was tracked at #12817 (but should be fixed now). Either way, it looks like this PR has a merge conflict now so it might need to rebase – is that something you can do? |
Sure thing !! Will do that in a bit though. ( heading out to watch Guardians of the Galaxy ) :D |
@addaleax @santigimeno Rebased!! Thanks for that. Can a CI job be triggered? |
@adityaanandmc sorry to bring this up again, but it would be great if you could address this. Anyway, the PR as it is LGTM. Thanks! |
@santigimeno That's alright. I did not see that comment until now. Sorry about that! Updated: Thanks @santigimeno @thefourtheye @Trott @cjihrig !! |
Yes, LGTM. I think another in |
@santigimeno Done! |
assert.strictEqual(e.address, '127.0.0.1'); | ||
})); | ||
server.close(); |
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.
Okay, server.close
is actually asynchronous. Perhaps we should run this test in the close
event of server
.
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.
Okay, server.close is actually asynchronous
You're right, though the close()
is executed syncronously at least on Unixes, but that's an implementation detail.
Perhaps we should run this test in the close event of server.
I think that's not going to work either, because there's going to be a window when the port is not assigned and could be grabbed by some other process/test.
So probably the only way to make this work without race conditions is moving it to sequential. What do you think @thefourtheye ?
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.
@santigimeno close()
is actually executed synchronously, but by the time the connection attempt is made (which happens asynchronously), the port is still up for grab, right? Perhaps I am overthinking 🤔
I am afraid sequential also will not solve this. common.PORT
could still have been assigned to other processes.
Perhaps we can live with the current change...
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.
@santigimeno close() is actually executed synchronously, but by the time the connection attempt is made (which happens asynchronously), the port is still up for grab, right? Perhaps I am overthinking 🤔
Yes, I thought of that too. And I think I'm also overthinking 😆 .
I am afraid sequential also will not solve this. common.PORT could still have been assigned to other processes.
Right, but not to other tests in the same run though.
Perhaps we can live with the current change...
Yeah, probably they'll never fail.
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.
Since we've reached a moo point. Would it be alright if I followed @thefourtheye approach and change the code accordingly ?
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.
@adityaanandmc No, move this to sequential, without the changes.
Remove common.PORT from, test-net-connect-immediate-destroy, test-net-options-lookup, test-net-connect-local-error, test-net-connect-handle-econnrefused, test-net-socket-destroy-twice, test-net-better-error-messages-port-hostname, test-net-localerror, to reduce possibility that a dynamic port used in another test will collide with common.PORT. Moved test-net-listen-shared-ports, test-net-better-error-messages-port from tests/parallel to test/sequential Refs: nodejs#12376
@thefourtheye Done. CI Build trigger necessary ? |
Remove common.PORT from, test-net-connect-immediate-destroy, test-net-options-lookup, test-net-connect-local-error, test-net-connect-handle-econnrefused, test-net-socket-destroy-twice, test-net-better-error-messages-port-hostname, test-net-localerror, to reduce possibility that a dynamic port used in another test will collide with common.PORT. Moved test-net-listen-shared-ports, test-net-better-error-messages-port from tests/parallel to test/sequential Refs: #12376 PR-URL: #12473 Reviewed-By: James M Snell <[email protected]> Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: Yuta Hiroto <[email protected]> Reviewed-By: Santiago Gimeno <[email protected]> Reviewed-By: Sakthipriyan Vairamani <[email protected]>
Landed in 94eed0f |
Remove common.PORT from, test-net-connect-immediate-destroy, test-net-options-lookup, test-net-connect-local-error, test-net-connect-handle-econnrefused, test-net-socket-destroy-twice, test-net-better-error-messages-port-hostname, test-net-localerror, to reduce possibility that a dynamic port used in another test will collide with common.PORT. Moved test-net-listen-shared-ports, test-net-better-error-messages-port from tests/parallel to test/sequential Refs: nodejs#12376 PR-URL: nodejs#12473 Reviewed-By: James M Snell <[email protected]> Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: Yuta Hiroto <[email protected]> Reviewed-By: Santiago Gimeno <[email protected]> Reviewed-By: Sakthipriyan Vairamani <[email protected]>
Remove common.PORT from, test-net-connect-immediate-destroy, test-net-options-lookup, test-net-connect-local-error, test-net-connect-handle-econnrefused, test-net-socket-destroy-twice, test-net-better-error-messages-port-hostname, test-net-localerror, to reduce possibility that a dynamic port used in another test will collide with common.PORT. Moved test-net-listen-shared-ports, test-net-better-error-messages-port from tests/parallel to test/sequential Refs: #12376 PR-URL: #12473 Reviewed-By: James M Snell <[email protected]> Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: Yuta Hiroto <[email protected]> Reviewed-By: Santiago Gimeno <[email protected]> Reviewed-By: Sakthipriyan Vairamani <[email protected]>
Remove common.PORT from, test-net-connect-immediate-destroy, test-net-options-lookup, test-net-connect-local-error, test-net-connect-handle-econnrefused, test-net-socket-destroy-twice, test-net-better-error-messages-port-hostname, test-net-localerror, to reduce possibility that a dynamic port used in another test will collide with common.PORT. Moved test-net-listen-shared-ports, test-net-better-error-messages-port from tests/parallel to test/sequential Refs: #12376 PR-URL: #12473 Reviewed-By: James M Snell <[email protected]> Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: Yuta Hiroto <[email protected]> Reviewed-By: Santiago Gimeno <[email protected]> Reviewed-By: Sakthipriyan Vairamani <[email protected]>
Refs: #12376
Tests Updated:
Tests ported from test/parallel to test/sequential:
Analyzed and continuing to use common.PORT
Checklist
make -j4 test
(UNIX), orvcbuild test
(Windows) passesAffected core subsystem(s)
test