|
| 1 | +// Copyright Joyent, Inc. and other Node contributors. |
| 2 | +// |
| 3 | +// Permission is hereby granted, free of charge, to any person obtaining a |
| 4 | +// copy of this software and associated documentation files (the |
| 5 | +// "Software"), to deal in the Software without restriction, including |
| 6 | +// without limitation the rights to use, copy, modify, merge, publish, |
| 7 | +// distribute, sublicense, and/or sell copies of the Software, and to permit |
| 8 | +// persons to whom the Software is furnished to do so, subject to the |
| 9 | +// following conditions: |
| 10 | +// |
| 11 | +// The above copyright notice and this permission notice shall be included |
| 12 | +// in all copies or substantial portions of the Software. |
| 13 | +// |
| 14 | +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS |
| 15 | +// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF |
| 16 | +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN |
| 17 | +// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, |
| 18 | +// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR |
| 19 | +// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE |
| 20 | +// USE OR OTHER DEALINGS IN THE SOFTWARE. |
| 21 | + |
| 22 | +/* |
| 23 | + * This test is a regression test for joyent/node#8897. |
| 24 | + */ |
| 25 | + |
| 26 | +var common = require('../common'); |
| 27 | +var assert = require('assert'); |
| 28 | +var net = require('net'); |
| 29 | + |
| 30 | +var clients = []; |
| 31 | + |
| 32 | +var server = net.createServer(function onClient(client) { |
| 33 | + clients.push(client); |
| 34 | + |
| 35 | + if (clients.length === 2) { |
| 36 | + /* |
| 37 | + * Enroll two timers, and make the one supposed to fire first |
| 38 | + * unenroll the other one supposed to fire later. This mutates |
| 39 | + * the list of unref timers when traversing it, and exposes the |
| 40 | + * original issue in joyent/node#8897. |
| 41 | + */ |
| 42 | + clients[0].setTimeout(1, function onTimeout() { |
| 43 | + clients[1].setTimeout(0); |
| 44 | + clients[0].end(); |
| 45 | + clients[1].end(); |
| 46 | + }); |
| 47 | + |
| 48 | + // Use a delay that is higher than the lowest timer resolution accross all |
| 49 | + // supported platforms, so that the two timers don't fire at the same time. |
| 50 | + clients[1].setTimeout(50); |
| 51 | + } |
| 52 | +}); |
| 53 | + |
| 54 | +server.listen(common.PORT, '127.0.0.1', function() { |
| 55 | + var nbClientsEnded = 0; |
| 56 | + |
| 57 | + function addEndedClient(client) { |
| 58 | + ++nbClientsEnded; |
| 59 | + if (nbClientsEnded === 2) { |
| 60 | + server.close(); |
| 61 | + } |
| 62 | + } |
| 63 | + |
| 64 | + var client1 = net.connect({ port: common.PORT }) |
| 65 | + client1.on('end', addEndedClient); |
| 66 | + |
| 67 | + var client2 = net.connect({ port: common.PORT }); |
| 68 | + client2.on('end', addEndedClient); |
| 69 | +}); |
0 commit comments