deno
deno copied to clipboard
error: "Leaking resources" using node:zlib in tests
Version: Deno 1.40.5 on Windows 11
The following test ends in error (the same code works well in Node v21.6.2)
Leaking resources:
- "zlib" was created during the test, but not cleaned up during the test. Close the resource before the end of the test.
import fs from 'node:fs';
import zlib from 'node:zlib';
import { pipeline } from 'node:stream/promises';
import { test } from 'node:test';
test('download file (fetch) + unzip gz file', async () => {
const path = './converter.exe';
const path_zip = path + '.gz';
const dest = fs.createWriteStream(path_zip);
//#region download and unzip file
const url = 'https://github.com/77it/financial-modeling-binaries/releases/download/v0.0.5/Converter.exe.gz';
const response = await fetch(url);
if (!response.ok) {
throw new Error(`Request failed with status ${response.status}`);
} else if (!response.body) {
throw new Error(`The requested download url ${url} doesn't contain an archive to download`);
} else if (response.status === 404) {
throw new Error(`The requested url "${url}" could not be found`);
}
await pipeline(
response.body,
dest
);
await unzipGzFile(path_zip, path);
//#endregion
//#region delete file
fs.unlinkSync(path);
fs.unlinkSync(path_zip);
//#endregion
});
/**
* Unzip a .gz file
*
* @param {string} path_zip - The path of the .gz file to unzip
* @param {string} path - The path of the local file to create
*/
async function unzipGzFile(path_zip, path) {
const source = fs.createReadStream(path_zip);
const destination = fs.createWriteStream(path);
const gunzip = zlib.createGunzip();
await pipeline(
source,
gunzip,
destination
);
}
Following the resolution of issue #22473 I would like to clarify that the "Leaking resources" error is also present in Deno.test(), then this issue should not be closed - possibly - without explaining how to make this code work under Deno. Thanks
encountered this too. mcve:
import { gzipSync } from 'node:zlib';
Deno.test('gzip', () => {
const data = new TextEncoder().encode('hello world');
gzipSync(data);
})
errors with:
running 1 test from ./gzip-repro.test.ts
gzip ... FAILED (1ms)
ERRORS
gzip => ./gzip-repro.test.ts:3:6
error: Leaks detected:
- "zlib" was created during the test, but not cleaned up during the test. Close the resource before the end of the test.
FAILURES
gzip => ./gzip-repro.test.ts:3:6
FAILED | 0 passed | 1 failed (99ms)
error: Test failed
issue is still present on latest canary:
deno 1.42.4+90a167a (canary, aarch64-apple-darwin)
v8 12.4.254.12
typescript 5.4.3