1// Flags: --expose-gc
2'use strict';
3const common = require('../common');
4const onGC = require('../common/ongc');
5const assert = require('assert');
6const zlib = require('zlib');
7
8// Checks that, if a zlib context fails with an error, it can still be GC'ed:
9// Refs: https://github.com/nodejs/node/issues/22705
10
11const ongc = common.mustCall();
12
13{
14  const input = Buffer.from('foobar');
15  const strm = zlib.createInflate();
16  strm.end(input);
17  strm.once('error', common.mustCall((err) => {
18    assert(err);
19    setImmediate(() => {
20      global.gc();
21      // Keep the event loop alive for seeing the async_hooks destroy hook
22      // we use for GC tracking...
23      // TODO(addaleax): This should maybe not be necessary?
24      setImmediate(() => {});
25    });
26  }));
27  onGC(strm, { ongc });
28}
29