mirror of
https://github.com/nodejs/node.git
synced 2025-05-06 05:21:19 +00:00

Asynchronous functions in `zlib` should not emit the close event. This fixes an issue where asynchronous calls in a for loop could exhaust memory because the pending event prevents the objects from being garbage collected. Fixes: https://github.com/nodejs/node/issues/1668 PR-URL: https://github.com/nodejs/node/pull/5707 Reviewed-By: jasnell - James M Snell <jasnell@gmail.com> Reviewed-By: trevnorris - Trevor Norris <trev.norris@gmail.com> Reviewed-By: Сковорода Никита Андреевич <chalkerx@gmail.com>
22 lines
622 B
JavaScript
22 lines
622 B
JavaScript
'use strict';
|
|
require('../common');
|
|
const zlib = require('zlib');
|
|
const assert = require('assert');
|
|
|
|
const shouldNotBeCalled = () => { throw new Error('unexpected event'); };
|
|
|
|
const message = 'Come on, Fhqwhgads.';
|
|
|
|
const zipper = new zlib.Gzip();
|
|
zipper.on('close', shouldNotBeCalled);
|
|
|
|
const buffer = new Buffer(message);
|
|
const zipped = zipper._processChunk(buffer, zlib.Z_FINISH);
|
|
|
|
const unzipper = new zlib.Gunzip();
|
|
unzipper.on('close', shouldNotBeCalled);
|
|
|
|
const unzipped = unzipper._processChunk(zipped, zlib.Z_FINISH);
|
|
assert.notEqual(zipped.toString(), message);
|
|
assert.strictEqual(unzipped.toString(), message);
|