1'use strict'; 2 3/* 4 * This test is a regression test for joyent/node#8897. 5 */ 6 7const common = require('../common'); 8const net = require('net'); 9const Countdown = require('../common/countdown'); 10 11const clients = []; 12 13const server = net.createServer(function onClient(client) { 14 clients.push(client); 15 16 if (clients.length === 2) { 17 /* 18 * Enroll two timers, and make the one supposed to fire first 19 * unenroll the other one supposed to fire later. This mutates 20 * the list of unref timers when traversing it, and exposes the 21 * original issue in joyent/node#8897. 22 */ 23 clients[0].setTimeout(1, () => { 24 clients[1].setTimeout(0); 25 clients[0].end(); 26 clients[1].end(); 27 }); 28 29 // Use a delay that is higher than the lowest timer resolution across all 30 // supported platforms, so that the two timers don't fire at the same time. 31 clients[1].setTimeout(50); 32 } 33}); 34 35server.listen(0, common.localhostIPv4, common.mustCall(() => { 36 const countdown = new Countdown(2, () => server.close()); 37 38 { 39 const client = net.connect({ port: server.address().port }); 40 client.on('end', () => countdown.dec()); 41 } 42 43 { 44 const client = net.connect({ port: server.address().port }); 45 client.on('end', () => countdown.dec()); 46 } 47})); 48