2015-05-19 13:00:06 +02:00
|
|
|
'use strict';
|
2013-05-17 15:07:28 -07:00
|
|
|
|
2016-03-28 17:07:22 -07:00
|
|
|
// Test that unref'ed sockets with timeouts do not prevent exit.
|
|
|
|
|
|
|
|
const common = require('../common');
|
|
|
|
const net = require('net');
|
|
|
|
|
|
|
|
const server = net.createServer(function(c) {
|
2013-05-17 15:07:28 -07:00
|
|
|
c.write('hello');
|
|
|
|
c.unref();
|
|
|
|
});
|
2016-05-29 03:06:56 -04:00
|
|
|
server.listen(0);
|
2013-05-17 15:07:28 -07:00
|
|
|
server.unref();
|
|
|
|
|
2017-01-08 13:19:00 +00:00
|
|
|
let connections = 0;
|
2016-03-28 17:07:22 -07:00
|
|
|
const sockets = [];
|
|
|
|
const delays = [8, 5, 3, 6, 2, 4];
|
2013-05-17 15:07:28 -07:00
|
|
|
|
2016-01-16 01:54:44 +01:00
|
|
|
delays.forEach(function(T) {
|
2016-05-29 03:06:56 -04:00
|
|
|
const socket = net.createConnection(server.address().port, 'localhost');
|
2016-03-28 17:07:22 -07:00
|
|
|
socket.on('connect', common.mustCall(function() {
|
2016-01-16 01:54:44 +01:00
|
|
|
if (++connections === delays.length) {
|
|
|
|
sockets.forEach(function(s) {
|
2016-03-28 17:07:22 -07:00
|
|
|
s.socket.setTimeout(s.timeout, function() {
|
|
|
|
s.socket.destroy();
|
|
|
|
throw new Error('socket timed out unexpectedly');
|
2016-01-16 01:54:44 +01:00
|
|
|
});
|
|
|
|
|
2016-03-28 17:07:22 -07:00
|
|
|
s.socket.unref();
|
2016-01-16 01:54:44 +01:00
|
|
|
});
|
|
|
|
}
|
2016-03-28 17:07:22 -07:00
|
|
|
}));
|
2013-05-17 15:07:28 -07:00
|
|
|
|
2016-03-28 17:07:22 -07:00
|
|
|
sockets.push({socket: socket, timeout: T * 1000});
|
2013-05-17 15:07:28 -07:00
|
|
|
});
|