24
25
res.writeHead(200, { "Content-Type": "text/plain"
25
, "Content-Length": body.length
26
, "Content-Length": body.length
31
var client = http.createClient(PORT);
30
server.listen(common.PORT);
38
// Client #1 is assigned Parser #1
40
var req1 = client.request("/1")
41
req1.addListener('response', function (res1) {
42
res1.setBodyEncoding("utf8");
44
res1.addListener('data', function (chunk) {
48
res1.addListener('end', function () {
50
// Delay execution a little to allow the "close" event to be processed
51
// (required to trigger this bug!)
53
setTimeout(function () {
55
// The bug would introduce itself here: Client #2 would be allocated the
56
// parser that previously belonged to Client #1. But we're not finished
57
// with Client #1 yet!
59
var client2 = http.createClient(PORT);
62
// At this point, the bug would manifest itself and crash because the
63
// internal state of the parser was no longer valid for use by Client #1.
65
var req2 = client.request("/2");
66
req2.addListener('response', function (res2) {
67
res2.setBodyEncoding("utf8");
68
res2.addListener('data', function (chunk) { body2 += chunk; });
69
res2.addListener('end', function () {
72
// Just to be really sure we've covered all our bases, execute a
73
// request using client2.
75
var req3 = client2.request("/3");
76
req3.addListener('response', function (res3) {
77
res3.setBodyEncoding("utf8");
78
res3.addListener('data', function (chunk) { body3 += chunk });
79
res3.addListener('end', function() { server.close(); });
36
server.addListener("listening", function() {
37
var client = http.createClient(common.PORT);
40
// Client #1 is assigned Parser #1
42
var req1 = client.request("/1")
44
req1.addListener('response', function (res1) {
45
res1.setEncoding("utf8");
47
res1.addListener('data', function (chunk) {
51
res1.addListener('end', function () {
53
// Delay execution a little to allow the "close" event to be processed
54
// (required to trigger this bug!)
56
setTimeout(function () {
58
// The bug would introduce itself here: Client #2 would be allocated the
59
// parser that previously belonged to Client #1. But we're not finished
60
// with Client #1 yet!
62
var client2 = http.createClient(common.PORT);
65
// At this point, the bug would manifest itself and crash because the
66
// internal state of the parser was no longer valid for use by Client #1.
68
var req2 = client.request("/2");
70
req2.addListener('response', function (res2) {
71
res2.setEncoding("utf8");
72
res2.addListener('data', function (chunk) { body2 += chunk; });
73
res2.addListener('end', function () {
76
// Just to be really sure we've covered all our bases, execute a
77
// request using client2.
79
var req3 = client2.request("/3");
81
req3.addListener('response', function (res3) {
82
res3.setEncoding("utf8");
83
res3.addListener('data', function (chunk) { body3 += chunk });
84
res3.addListener('end', function() { server.close(); });
90
93
process.addListener("exit", function () {
91
94
assert.equal(body1_s, body1);