mirror of https://github.com/lukechilds/node.git
Browse Source
Throw immediately on socket timeout rather than checking boolean in exit handler. PR-URL: https://github.com/nodejs/node/pull/6003 Fixes: https://github.com/nodejs/node/issues/5128 Reviewed-By: Myles Borins <myles.borins@gmail.com>process-exit-stdio-flushing
Rich Trott
9 years ago
1 changed files with 16 additions and 20 deletions
@ -1,39 +1,35 @@ |
|||||
'use strict'; |
'use strict'; |
||||
var common = require('../common'); |
|
||||
var assert = require('assert'); |
|
||||
var net = require('net'); |
|
||||
|
|
||||
var server = net.createServer(function(c) { |
// 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) { |
||||
c.write('hello'); |
c.write('hello'); |
||||
c.unref(); |
c.unref(); |
||||
}); |
}); |
||||
server.listen(common.PORT); |
server.listen(common.PORT); |
||||
server.unref(); |
server.unref(); |
||||
|
|
||||
var timedout = false; |
|
||||
var connections = 0; |
var connections = 0; |
||||
var sockets = []; |
const sockets = []; |
||||
var delays = [8, 5, 3, 6, 2, 4]; |
const delays = [8, 5, 3, 6, 2, 4]; |
||||
|
|
||||
delays.forEach(function(T) { |
delays.forEach(function(T) { |
||||
var socket = net.createConnection(common.PORT, 'localhost'); |
const socket = net.createConnection(common.PORT, 'localhost'); |
||||
socket.on('connect', function() { |
socket.on('connect', common.mustCall(function() { |
||||
if (++connections === delays.length) { |
if (++connections === delays.length) { |
||||
sockets.forEach(function(s) { |
sockets.forEach(function(s) { |
||||
s[0].setTimeout(s[1] * 1000, function() { |
s.socket.setTimeout(s.timeout, function() { |
||||
timedout = true; |
s.socket.destroy(); |
||||
s[0].destroy(); |
throw new Error('socket timed out unexpectedly'); |
||||
}); |
}); |
||||
|
|
||||
s[0].unref(); |
s.socket.unref(); |
||||
}); |
}); |
||||
} |
} |
||||
}); |
})); |
||||
|
|
||||
sockets.push([socket, T]); |
|
||||
}); |
|
||||
|
|
||||
process.on('exit', function() { |
sockets.push({socket: socket, timeout: T * 1000}); |
||||
assert.strictEqual(timedout, false, |
|
||||
'Socket timeout should not hold loop open'); |
|
||||
}); |
}); |
||||
|
Loading…
Reference in new issue