File tree Expand file tree Collapse file tree 1 file changed +41
-0
lines changed
test/js/node/test/parallel Expand file tree Collapse file tree 1 file changed +41
-0
lines changed Original file line number Diff line number Diff line change 1+ // Flags: --expose-gc
2+ 'use strict' ;
3+ const common = require ( '../common' ) ;
4+ const { onGC } = require ( '../common/gc' ) ;
5+ const { createServer } = require ( 'http' ) ;
6+ const { connect } = require ( 'net' ) ;
7+
8+ // Make sure that for HTTP keepalive requests, the req object can be
9+ // garbage collected once the request is finished.
10+ // Refs: https://github.com/nodejs/node/issues/9668
11+
12+ let client ;
13+ const server = createServer ( common . mustCall ( ( req , res ) => {
14+ onGC ( req , { ongc : common . mustCall ( ( ) => { server . close ( ) ; } ) } ) ;
15+ req . resume ( ) ;
16+ req . on ( 'end' , common . mustCall ( ( ) => {
17+ setImmediate ( async ( ) => {
18+ client . end ( ) ;
19+ await globalThis . gc ( { type : 'major' , execution : 'async' } ) ;
20+ await globalThis . gc ( { type : 'major' , execution : 'async' } ) ;
21+ } ) ;
22+ } ) ) ;
23+ res . end ( 'hello world' ) ;
24+ } ) ) ;
25+
26+ server . listen ( 0 , common . mustCall ( ( ) => {
27+ client = connect ( server . address ( ) . port ) ;
28+
29+ const req = [
30+ 'POST / HTTP/1.1' ,
31+ `Host: localhost:${ server . address ( ) . port } ` ,
32+ 'Connection: keep-alive' ,
33+ 'Content-Length: 11' ,
34+ '' ,
35+ 'hello world' ,
36+ '' ,
37+ ] . join ( '\r\n' ) ;
38+
39+ client . write ( req ) ;
40+ client . unref ( ) ;
41+ } ) ) ;
You can’t perform that action at this time.
0 commit comments