How to dispose a ReadStream passed to body option correctly - Jest JSSTREAM open handle warning
#2061
-
|
I'm getting Jest warning when executing one of my tests that it detected an open handle: I'm wondering if I'm disposing the stream correctly and this is just a false alarm or should I do something more? The test and my app exit correctly. This is a simplified example what my code looks like: |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
|
the JSSTREAM warning is actually a false positive from Jest's your cleanup code looks correct. got will destroy the stream when the request completes. just make sure to await the request before closing the fileHandle: try {
const fileStream = fileHandle.createReadStream({
start: this.chunkStartPosition,
end: this.chunkStartPosition + this.chunkLengthInBytes - 1
});
await gotInstance.post(this.uploadUrl, { body: fileStream });
} finally {
await fileHandle?.close(); // await this
}to fix the Jest warning, either:
const gotInstance = got.extend({
http2: false
});the warning dosen't indicate a real leak - your streams are being cleaned up properly. |
Beta Was this translation helpful? Give feedback.
the JSSTREAM warning is actually a false positive from Jest's
--detectOpenHandles- its related to http2-wrapper's global connection pool, not your file stream (see issue #2288).your cleanup code looks correct. got will destroy the stream when the request completes. just make sure to await the request before closing the fileHandle:
to fix the Jest warning, either:
--detectOpenHandlesflaght…