-
Notifications
You must be signed in to change notification settings - Fork 29.9k
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: refactor flaky net-error-twice #4062
Closed
Closed
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,33 +1,37 @@ | ||
'use strict'; | ||
var common = require('../common'); | ||
var assert = require('assert'); | ||
var net = require('net'); | ||
const common = require('../common'); | ||
const assert = require('assert'); | ||
const net = require('net'); | ||
|
||
var buf = new Buffer(10 * 1024 * 1024); | ||
const buf = new Buffer(10 * 1024 * 1024); | ||
|
||
buf.fill(0x62); | ||
|
||
var errs = []; | ||
|
||
var srv = net.createServer(function onConnection(conn) { | ||
conn.write(buf); | ||
const srv = net.createServer(function onConnection(conn) { | ||
if (common.isWindows) { | ||
// Windows-specific handling. See: | ||
// * https://github.com/nodejs/node/pull/4062 | ||
// * https://github.com/nodejs/node/issues/4057 | ||
setTimeout(() => { conn.write(buf); }, 100); | ||
} else { | ||
conn.write(buf); | ||
} | ||
|
||
conn.on('error', function(err) { | ||
errs.push(err); | ||
if (errs.length > 1 && errs[0] === errs[1]) | ||
assert(false, 'We should not be emitting the same error twice'); | ||
if (errs.length > 1) | ||
assert(errs[0] !== errs[1], 'Should not get the same error twice'); | ||
}); | ||
conn.on('close', function() { | ||
srv.unref(); | ||
}); | ||
}).listen(common.PORT, function() { | ||
var client = net.connect({ port: common.PORT }); | ||
|
||
client.on('connect', function() { | ||
client.destroy(); | ||
}); | ||
const client = net.connect({ port: common.PORT }); | ||
client.on('connect', client.destroy); | ||
}); | ||
|
||
process.on('exit', function() { | ||
console.log(errs); | ||
assert.equal(errs.length, 1); | ||
}); |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Why is the delay necessary?
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.
@bnoordhuis Concise-but-naive answer: Without the delay, the test is flaky on Windows 2012 r2 on the CI infrastructure.
Less concise and marginally less naive: In this test,
conn.write(buf)
is supposed to get an error (eitherEPIPE
orECONNRESET
depending on timing).Unfortunately, on Windows 2012 r2 only, it appears that the call toUPDATE: Actually, I think the problem is that the client connection and server connection callbacks fire in an unpredictable order. On Windows 2012 r2 only, theclient.destroy()
often returns before the socket is set to emit the error.conn.write()
would often not trigger an error and the result wasassert.equal(errs.length, 1)
firing (becauseerrs.length
is 0). I triedsetImmediate()
and that may have improved things but it did not resolve the flakiness. Using the timeout resolved the flakiness. (I did not experiment with a timeout of less than 100 milliseconds.)As for the cause of this on Windows 2012 r2, I don't know and would certainly be receptive to some guidance on figuring it out (or someone simply doing the work and identifying the source of the issue). Operating system limitation? Bug in libuv? Bug in
socket.destroy
? I don't know. I don't have easy access to a Windows 2012 r2 machine. (I could try to run one via VirtualBox, but my laptop resources are kind of limited right now and my weak excuse is that it would probably fill up my disk.)