-
-
Notifications
You must be signed in to change notification settings - Fork 35.2k
test: fix flaky https tests on windows #62451
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -35,6 +35,7 @@ const { | |
| NumberParseInt, | ||
| ObjectDefineProperty, | ||
| ObjectSetPrototypeOf, | ||
| SafeSet, | ||
| Symbol, | ||
| SymbolAsyncDispose, | ||
| SymbolDispose, | ||
|
|
@@ -912,6 +913,7 @@ Socket.prototype._destroy = function(exception, cb) { | |
| if (this._server) { | ||
| debug('has server'); | ||
| this._server._connections--; | ||
| this._server._connectionSockets?.delete(this); | ||
| if (this._server._emitCloseIfDrained) { | ||
| this._server._emitCloseIfDrained(); | ||
| } | ||
|
|
@@ -1867,6 +1869,7 @@ function Server(options, connectionListener) { | |
| } | ||
|
|
||
| this._connections = 0; | ||
| this._connectionSockets = new SafeSet(); | ||
|
|
||
| this[async_id_symbol] = -1; | ||
| this._handle = null; | ||
|
|
@@ -2365,6 +2368,7 @@ function onconnection(err, clientHandle) { | |
| } | ||
|
|
||
| self._connections++; | ||
| self._connectionSockets.add(socket); | ||
| socket.server = self; | ||
| socket._server = self; | ||
| self.emit('connection', socket); | ||
|
|
@@ -2436,6 +2440,22 @@ Server.prototype.close = function(cb) { | |
| this._handle = null; | ||
| } | ||
|
|
||
| // Register a beforeExit handler to destroy any remaining connections | ||
| // before the process exits. This ensures connections are torn down | ||
| // during normal JS execution rather than during environment cleanup, | ||
| // where on Windows the IOCP completion processing can race with | ||
| // handle teardown. | ||
| if (this._connectionSockets.size > 0) { | ||
| const connections = this._connectionSockets; | ||
| const onBeforeExit = () => { | ||
| process.removeListener('beforeExit', onBeforeExit); | ||
| for (const socket of connections) { | ||
| socket.destroy(); | ||
| } | ||
| }; | ||
| process.on('beforeExit', onBeforeExit); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If the issue is Windows only, the hook and tracking should be added only on Windows, no? Anyway do you know when the issue started? Is it a regression, and did you manage to reproduce it locally?
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, I was able to locally repro. It is a regression but I haven't yet been able to track down exactly when it started. It looks like a libuv issue. |
||
| } | ||
|
|
||
| if (this._usingWorkers) { | ||
| let left = this._workers.length; | ||
| const onWorkerClose = () => { | ||
|
|
||
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.
This will unfortunately add overhead. I would prefer if we could avoid this entirely/find the root cause of this regression or adjust the tests.
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.
Adjusting the tests means adding
closeAllConnections()to everytest-http(s)test and that still leaves flakiness for all of thetest-tls-*andtest-net-*tests that have also been flaky.