mirror of
https://github.com/nodejs/node.git
synced 2024-12-01 16:10:02 +01:00
c14e98b476
This commit fix a possible crash situation in dgram send(). A crash is possible if an array is passed, and then altered after the send call, as the call to libuv is wrapped in process.nextTick(). It also avoid sending an empty array to libuv by allocating an empty buffer. It also does some cleanup inside send() to increase readability. It removes test flakyness by use common.mustCall and common.platformTimeout. Fixes situations were some events were not asserted to be emitted. Fixes: https://github.com/nodejs/node/issues/6616 PR-URL: https://github.com/nodejs/node/pull/6804 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
25 lines
624 B
JavaScript
25 lines
624 B
JavaScript
'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 buf = Buffer.allocUnsafe(256);
|
|
const offset = 20;
|
|
const len = buf.length - offset;
|
|
|
|
const messageSent = common.mustCall(function messageSent(err, bytes) {
|
|
assert.notEqual(bytes, buf.length);
|
|
assert.equal(bytes, buf.length - offset);
|
|
clearTimeout(timer);
|
|
client.close();
|
|
});
|
|
|
|
client.send(buf, offset, len, common.PORT, '127.0.0.1', messageSent);
|