11cb0ef41Sopenharmony_ci'use strict'; 21cb0ef41Sopenharmony_ci// Flags: --expose-gc 31cb0ef41Sopenharmony_ci 41cb0ef41Sopenharmony_ci// Regression test for https://github.com/nodejs/node/issues/8251. 51cb0ef41Sopenharmony_ciconst common = require('../common'); 61cb0ef41Sopenharmony_ciconst net = require('net'); 71cb0ef41Sopenharmony_ci 81cb0ef41Sopenharmony_ciconst data = Buffer.alloc(1000000).toString('hex'); 91cb0ef41Sopenharmony_ci 101cb0ef41Sopenharmony_ciconst server = net.createServer(common.mustCall(function(conn) { 111cb0ef41Sopenharmony_ci conn.resume(); 121cb0ef41Sopenharmony_ci})).listen(0, common.mustCall(function() { 131cb0ef41Sopenharmony_ci const conn = net.createConnection(this.address().port, common.mustCall(() => { 141cb0ef41Sopenharmony_ci let count = 0; 151cb0ef41Sopenharmony_ci 161cb0ef41Sopenharmony_ci function writeLoop() { 171cb0ef41Sopenharmony_ci if (count++ === 20) { 181cb0ef41Sopenharmony_ci conn.destroy(); 191cb0ef41Sopenharmony_ci server.close(); 201cb0ef41Sopenharmony_ci return; 211cb0ef41Sopenharmony_ci } 221cb0ef41Sopenharmony_ci 231cb0ef41Sopenharmony_ci while (conn.write(data, 'hex')); 241cb0ef41Sopenharmony_ci global.gc({ type: 'minor' }); 251cb0ef41Sopenharmony_ci // The buffer allocated inside the .write() call should still be alive. 261cb0ef41Sopenharmony_ci } 271cb0ef41Sopenharmony_ci 281cb0ef41Sopenharmony_ci conn.on('drain', writeLoop); 291cb0ef41Sopenharmony_ci 301cb0ef41Sopenharmony_ci writeLoop(); 311cb0ef41Sopenharmony_ci })); 321cb0ef41Sopenharmony_ci})); 33