1'use strict'; 2// Flags: --expose-gc 3 4// Regression test for https://github.com/nodejs/node/issues/8251. 5const common = require('../common'); 6const net = require('net'); 7 8const data = Buffer.alloc(1000000).toString('hex'); 9 10const server = net.createServer(common.mustCall(function(conn) { 11 conn.resume(); 12})).listen(0, common.mustCall(function() { 13 const conn = net.createConnection(this.address().port, common.mustCall(() => { 14 let count = 0; 15 16 function writeLoop() { 17 if (count++ === 20) { 18 conn.destroy(); 19 server.close(); 20 return; 21 } 22 23 while (conn.write(data, 'hex')); 24 global.gc(true); 25 // The buffer allocated inside the .write() call should still be alive. 26 } 27 28 conn.on('drain', writeLoop); 29 30 writeLoop(); 31 })); 32})); 33