node/test/parallel/test-dgram-close-in-listening.js
Matteo Collina a2a711a373 dgram: generalized send queue to handle close
If the udp socket is not ready and we are accumulating
messages to send, it needs to delay closing the socket when
all messages are flushed.

Fixes: https://github.com/nodejs/node/issues/7061
PR-URL: https://github.com/nodejs/node/pull/7066
Reviewed-By: Anna Henningsen <anna@addaleax.net>
2016-07-13 17:49:04 +02:00

19 lines
460 B
JavaScript

'use strict';
// Ensure that if a dgram socket is closed before the sendQueue is drained
// will not crash
const common = require('../common');
const dgram = require('dgram');
const buf = Buffer.alloc(1024, 42);
const socket = dgram.createSocket('udp4');
socket.on('listening', function() {
socket.close();
});
// adds a listener to 'listening' to send the data when
// the socket is available
socket.send(buf, 0, buf.length, common.PORT, 'localhost');