forked from nodejs/node
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtest-http-server-keepalive-req-gc.js
More file actions
47 lines (40 loc) · 1.1 KB
/
test-http-server-keepalive-req-gc.js
File metadata and controls
47 lines (40 loc) · 1.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
// Flags: --expose-gc
'use strict';
const common = require('../common');
const onGC = require('../common/ongc');
const { createServer } = require('http');
const { connect } = require('net');
if (common.isWindows) {
// TODO(addaleax): Investigate why and remove the skip.
common.skip('This test is flaky on Windows.');
}
// Make sure that for HTTP keepalive requests, the req object can be
// garbage collected once the request is finished.
// Refs: https://github.com/nodejs/node/issues/9668
let client;
const server = createServer(common.mustCall((req, res) => {
onGC(req, { ongc: common.mustCall() });
req.resume();
req.on('end', common.mustCall(() => {
setImmediate(() => {
client.end();
global.gc();
});
}));
res.end('hello world');
}));
server.unref();
server.listen(0, common.mustCall(() => {
client = connect(server.address().port);
const req = [
'POST / HTTP/1.1',
`Host: localhost:${server.address().port}`,
'Connection: keep-alive',
'Content-Length: 11',
'',
'hello world',
''
].join('\r\n');
client.write(req);
client.unref();
}));