2010-12-05 00:20:34 +01:00
|
|
|
var common = require('../common');
|
|
|
|
var assert = require('assert');
|
|
|
|
var http = require('http');
|
2010-12-05 23:33:52 +01:00
|
|
|
var url = require('url');
|
2010-05-05 10:55:04 +02:00
|
|
|
|
|
|
|
//
|
|
|
|
// Slight variation on test-http-client-race to test for another race
|
|
|
|
// condition involving the parsers FreeList used internally by http.Client.
|
|
|
|
//
|
|
|
|
|
2010-12-05 23:33:52 +01:00
|
|
|
var body1_s = '1111111111111111';
|
|
|
|
var body2_s = '22222';
|
|
|
|
var body3_s = '3333333333333333333';
|
2010-05-05 10:55:04 +02:00
|
|
|
|
2010-12-05 23:33:52 +01:00
|
|
|
var server = http.createServer(function(req, res) {
|
2010-05-05 10:55:04 +02:00
|
|
|
var pathname = url.parse(req.url).pathname;
|
|
|
|
|
|
|
|
var body;
|
|
|
|
switch (pathname) {
|
2010-12-05 23:33:52 +01:00
|
|
|
case '/1': body = body1_s; break;
|
|
|
|
case '/2': body = body2_s; break;
|
2010-05-05 10:55:04 +02:00
|
|
|
default: body = body3_s;
|
2010-12-05 23:33:52 +01:00
|
|
|
}
|
2010-05-05 10:55:04 +02:00
|
|
|
|
2010-12-05 23:33:52 +01:00
|
|
|
res.writeHead(200,
|
|
|
|
{'Content-Type': 'text/plain', 'Content-Length': body.length});
|
2010-05-05 10:55:04 +02:00
|
|
|
res.end(body);
|
|
|
|
});
|
2010-07-15 20:47:25 +02:00
|
|
|
server.listen(common.PORT);
|
2010-05-05 10:55:04 +02:00
|
|
|
|
2010-12-05 23:33:52 +01:00
|
|
|
var body1 = '';
|
|
|
|
var body2 = '';
|
|
|
|
var body3 = '';
|
2010-05-05 10:55:04 +02:00
|
|
|
|
2011-10-15 01:08:36 +02:00
|
|
|
server.on('listening', function() {
|
2010-08-12 01:38:42 +02:00
|
|
|
var client = http.createClient(common.PORT);
|
2010-05-05 10:55:04 +02:00
|
|
|
|
2010-08-12 01:38:42 +02:00
|
|
|
//
|
|
|
|
// Client #1 is assigned Parser #1
|
|
|
|
//
|
2010-12-05 23:33:52 +01:00
|
|
|
var req1 = client.request('/1');
|
2010-08-12 01:38:42 +02:00
|
|
|
req1.end();
|
2011-10-15 01:08:36 +02:00
|
|
|
req1.on('response', function(res1) {
|
2010-12-05 23:33:52 +01:00
|
|
|
res1.setEncoding('utf8');
|
2010-05-05 10:55:04 +02:00
|
|
|
|
2011-10-15 01:08:36 +02:00
|
|
|
res1.on('data', function(chunk) {
|
2010-08-12 01:38:42 +02:00
|
|
|
body1 += chunk;
|
|
|
|
});
|
2010-05-05 10:55:04 +02:00
|
|
|
|
2011-10-15 01:08:36 +02:00
|
|
|
res1.on('end', function() {
|
2010-05-05 10:55:04 +02:00
|
|
|
//
|
2010-12-05 23:33:52 +01:00
|
|
|
// Delay execution a little to allow the 'close' event to be processed
|
2010-08-12 01:38:42 +02:00
|
|
|
// (required to trigger this bug!)
|
2010-05-05 10:55:04 +02:00
|
|
|
//
|
2010-12-05 23:33:52 +01:00
|
|
|
setTimeout(function() {
|
2010-08-12 01:38:42 +02:00
|
|
|
//
|
|
|
|
// The bug would introduce itself here: Client #2 would be allocated the
|
|
|
|
// parser that previously belonged to Client #1. But we're not finished
|
|
|
|
// with Client #1 yet!
|
|
|
|
//
|
|
|
|
var client2 = http.createClient(common.PORT);
|
|
|
|
|
|
|
|
//
|
|
|
|
// At this point, the bug would manifest itself and crash because the
|
2010-12-05 23:33:52 +01:00
|
|
|
// internal state of the parser was no longer valid for use by Client #1
|
2010-08-12 01:38:42 +02:00
|
|
|
//
|
2010-12-05 23:33:52 +01:00
|
|
|
var req2 = client.request('/2');
|
2010-08-12 01:38:42 +02:00
|
|
|
req2.end();
|
2011-10-15 01:08:36 +02:00
|
|
|
req2.on('response', function(res2) {
|
2010-12-05 23:33:52 +01:00
|
|
|
res2.setEncoding('utf8');
|
2011-10-15 01:08:36 +02:00
|
|
|
res2.on('data', function(chunk) { body2 += chunk; });
|
|
|
|
res2.on('end', function() {
|
2010-05-05 10:55:04 +02:00
|
|
|
|
2010-08-12 01:38:42 +02:00
|
|
|
//
|
|
|
|
// Just to be really sure we've covered all our bases, execute a
|
|
|
|
// request using client2.
|
|
|
|
//
|
2010-12-05 23:33:52 +01:00
|
|
|
var req3 = client2.request('/3');
|
2010-08-12 01:38:42 +02:00
|
|
|
req3.end();
|
2011-10-15 01:08:36 +02:00
|
|
|
req3.on('response', function(res3) {
|
2010-12-05 23:33:52 +01:00
|
|
|
res3.setEncoding('utf8');
|
2011-10-15 01:08:36 +02:00
|
|
|
res3.on('data', function(chunk) { body3 += chunk });
|
|
|
|
res3.on('end', function() { server.close(); });
|
2010-08-12 01:38:42 +02:00
|
|
|
});
|
2010-05-05 10:55:04 +02:00
|
|
|
});
|
|
|
|
});
|
2010-08-12 01:38:42 +02:00
|
|
|
}, 500);
|
|
|
|
});
|
2010-05-05 10:55:04 +02:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2011-10-15 01:08:36 +02:00
|
|
|
process.on('exit', function() {
|
2010-05-05 10:55:04 +02:00
|
|
|
assert.equal(body1_s, body1);
|
|
|
|
assert.equal(body2_s, body2);
|
|
|
|
assert.equal(body3_s, body3);
|
|
|
|
});
|
|
|
|
|