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

test: do not race server.close with timeout #44039

Closed
wants to merge 1 commit into from

Conversation

mmomtchev
Copy link
Contributor

Refs: #43680

This fails when server.close() manages to close the connection before the timeout has fired.
Here is the original issue: #33734
It is not about the behaviour when racing server.close() with the timeout - it is about the timeout not firing at all. I am removing the race condition as I don't think there should be any guarantees on which callback should fire first.

@nodejs-github-bot nodejs-github-bot added needs-ci PRs that need a full CI run. test Issues and PRs related to the tests. labels Jul 29, 2022
@lpinca
Copy link
Member

lpinca commented Jul 29, 2022

This fails when server.close() manages to close the connection before the timeout has fired

server.close() should not close the connection as the request is in progress, it should only prevent new connections from being accepted, no?

@mmomtchev
Copy link
Contributor Author

This fails when server.close() manages to close the connection before the timeout has fired

server.close() should not close the connection as the request is in progress, it should only prevent new connections from being accepted, no?

This connection appears to be an idle connection to server.close() and so it is closed by Server.prototype.closeIdleConnections. I am not sure if this is expected or a bug.

@lpinca
Copy link
Member

lpinca commented Jul 30, 2022

Ok it makes sense. It looks like Server.prototype.close() behavior was changed in #43522. I think there should be at least an option to preserve the old behavior. cc: @ShogunPanda

@@ -9,6 +9,6 @@ server.listen(common.mustCall(() => {
http.get({ port: server.address().port }, common.mustCall((res) => {
res.on('timeout', common.mustCall(() => req.destroy()));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
res.on('timeout', common.mustCall(() => req.destroy()));
res.on('timeout', common.mustCall(() => {
req.destroy();
server.close();
}));

The original issue was that the listener of the 'timeout' event was not called if added on the response object so this should be ok. It does not invalidate the test and only one timer is used.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Failure will require a timeout and kill from the runner in this case?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Failure will require a timeout and kill from the runner in this case?

Yes.

@@ -9,6 +9,6 @@ server.listen(common.mustCall(() => {
http.get({ port: server.address().port }, common.mustCall((res) => {
res.on('timeout', common.mustCall(() => req.destroy()));
res.setTimeout(1);
server.close();
setTimeout(common.mustCall(() => server.close()), 2);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
setTimeout(common.mustCall(() => server.close()), 2);

@lpinca
Copy link
Member

lpinca commented Jul 30, 2022

Anyway I also think that Server.prototype.closeIdleConnections() incorrectly closes the connection. The client connection is waiting for a response.

@ShogunPanda
Copy link
Contributor

@lpinca In #43890 I fixed that behavior. The method will not close connections which are still awaiting a response.

@ShogunPanda
Copy link
Contributor

About that test, I see timeouts too narrow. I wonder if events get scheduled in the wrong way in the same tick.

@lpinca
Copy link
Member

lpinca commented Jul 30, 2022

FWIW no failures have been registered for this test in last 5 days, so I guess #43890 fixed the underlying issue. I think it is better to keep the test as is if it no longer fails.

@mmomtchev
Copy link
Contributor Author

@lpinca, there is also libuv/libuv#3686 which is the real reason I am fixing this

@mmomtchev
Copy link
Contributor Author

@lpinca @ShogunPanda
In fact #43890 fixed both problems - the flaky unit test and the dependency on the uv event loop behaviour.
I am closing this PR, @danielleadams, you should probably unmark this unit test as being flaky

@mmomtchev mmomtchev closed this Jul 30, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs-ci PRs that need a full CI run. test Issues and PRs related to the tests.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants