diff options
author | Rich Trott <rtrott@gmail.com> | 2016-03-14 17:11:07 -0700 |
---|---|---|
committer | Rich Trott <rtrott@gmail.com> | 2016-03-19 13:38:26 -0700 |
commit | 8b43d3f52dc4a2fc6e72ee21ba97111fa7447b60 (patch) | |
tree | a2eed7fba6188d1d8fc2d7d08587039dc193e8d4 /test | |
parent | a53b2ac4b1dcde5579d9cba814ca0c4b78e59a9f (diff) | |
download | android-node-v8-8b43d3f52dc4a2fc6e72ee21ba97111fa7447b60.tar.gz android-node-v8-8b43d3f52dc4a2fc6e72ee21ba97111fa7447b60.tar.bz2 android-node-v8-8b43d3f52dc4a2fc6e72ee21ba97111fa7447b60.zip |
zlib: do not emit event on *Sync() methods
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>
Diffstat (limited to 'test')
-rw-r--r-- | test/parallel/test-zlib-sync-no-event.js | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/test/parallel/test-zlib-sync-no-event.js b/test/parallel/test-zlib-sync-no-event.js new file mode 100644 index 0000000000..81d1ad530d --- /dev/null +++ b/test/parallel/test-zlib-sync-no-event.js @@ -0,0 +1,21 @@ +'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); |