-
Notifications
You must be signed in to change notification settings - Fork 29.8k
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
dgram: copy the array when using the list variant in send() #6804
Closed
Closed
Changes from all commits
Commits
Show all changes
4 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
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
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,26 +1,24 @@ | ||
'use strict'; | ||
var common = require('../common'); | ||
var assert = require('assert'); | ||
|
||
var dgram = require('dgram'); | ||
var client, timer, buf, len, offset; | ||
const common = require('../common'); | ||
const assert = require('assert'); | ||
|
||
const dgram = require('dgram'); | ||
const client = dgram.createSocket('udp4'); | ||
|
||
client = dgram.createSocket('udp4'); | ||
|
||
buf = Buffer.allocUnsafe(256); | ||
offset = 20; | ||
|
||
len = buf.length - offset; | ||
const timer = setTimeout(function() { | ||
throw new Error('Timeout'); | ||
}, common.platformTimeout(200)); | ||
|
||
const buf = Buffer.allocUnsafe(256); | ||
const offset = 20; | ||
const len = buf.length - offset; | ||
|
||
client.send(buf, offset, len, common.PORT, '127.0.0.1', function(err, bytes) { | ||
const messageSent = common.mustCall(function messageSent(err, bytes) { | ||
assert.notEqual(bytes, buf.length); | ||
assert.equal(bytes, buf.length - offset); | ||
clearTimeout(timer); | ||
client.close(); | ||
}); | ||
|
||
timer = setTimeout(function() { | ||
throw new Error('Timeout'); | ||
}, 200); | ||
client.send(buf, offset, len, common.PORT, '127.0.0.1', messageSent); |
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
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 |
---|---|---|
@@ -0,0 +1,29 @@ | ||
'use strict'; | ||
|
||
const common = require('../common'); | ||
const assert = require('assert'); | ||
const dgram = require('dgram'); | ||
|
||
if (process.platform === 'darwin') { | ||
common.skip('because of 17894467 Apple bug'); | ||
return; | ||
} | ||
|
||
const client = dgram.createSocket('udp4'); | ||
|
||
const timer = setTimeout(function() { | ||
throw new Error('Timeout'); | ||
}, common.platformTimeout(200)); | ||
|
||
client.on('message', common.mustCall(function onMessage(buf, info) { | ||
const expected = Buffer.alloc(0); | ||
assert.ok(buf.equals(expected), 'message was received correctly'); | ||
clearTimeout(timer); | ||
client.close(); | ||
})); | ||
|
||
client.on('listening', function() { | ||
client.send([], common.PORT, common.localhostIPv4); | ||
}); | ||
|
||
client.bind(common.PORT); |
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
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 |
---|---|---|
@@ -0,0 +1,33 @@ | ||
'use strict'; | ||
|
||
const common = require('../common'); | ||
const assert = require('assert'); | ||
const dgram = require('dgram'); | ||
|
||
const client = dgram.createSocket('udp4'); | ||
|
||
const timer = setTimeout(function() { | ||
throw new Error('Timeout'); | ||
}, common.platformTimeout(200)); | ||
|
||
const onMessage = common.mustCall(function(err, bytes) { | ||
assert.equal(bytes, buf1.length + buf2.length); | ||
clearTimeout(timer); | ||
}); | ||
|
||
const buf1 = Buffer.alloc(256, 'x'); | ||
const buf2 = Buffer.alloc(256, 'y'); | ||
|
||
client.on('listening', function() { | ||
const toSend = [buf1, buf2]; | ||
client.send(toSend, common.PORT, common.localhostIPv4, onMessage); | ||
toSend.splice(0, 2); | ||
}); | ||
|
||
client.on('message', common.mustCall(function onMessage(buf, info) { | ||
const expected = Buffer.concat([buf1, buf2]); | ||
assert.ok(buf.equals(expected), 'message was received correctly'); | ||
client.close(); | ||
})); | ||
|
||
client.bind(common.PORT); |
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.
Can we get rid of the timer?
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. It allows fast-failures, otherwise you rely on the 1 minute timeout that each tests has.
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, but these kind of timers have been source of flaky tests. I don't think relying in the test runner timeout is a bad idea.
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 problem are not the timers, UDP messages can get lost: that's why the tests are flaky. If it has not arrived after 200ms (adjusted for platforms), it will never arrive. We might discuss on increasing those timeouts to reduce the likelyhood of missing a "right" message.
There will always be flaky tests on UDP if we want high coverage.
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.
I understand that: it's UDP.
But I think these kind timers (
the test is taking longer than expected so we throw
) should only exist when testing timing related features (timers, connection timers, etc.) otherwise the test runner should catch them. I think @Trott made some good points here: nodejs/testing#27 (comment).Anyway, I'm fine either way.
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.
All tests of UDP are done in the same way. If we want to change those, we can (and probably we should). It's definite a different PR as this is becoming more and more full of stuff.
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 makes sense to me.