Skip to content

Commit ede0f4f

Browse files
authoredDec 30, 2024··
fix: don't fail on closing fd after reset has been called (#550) (#1081)
* fix: don't fail on closing fd after reset has been called (#550) * fix: only skip EBADF errors on async close and only when aborted * fix: remove abortControllers and just call closeFile asynchronously from close
1 parent f389874 commit ede0f4f

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed
 

‎src/__tests__/volume.test.ts

+17
Original file line numberDiff line numberDiff line change
@@ -361,6 +361,23 @@ describe('volume', () => {
361361
'/good': 'bye',
362362
});
363363
});
364+
it('Open streams should not be affected', async () => {
365+
const vol = new Volume();
366+
const json = {
367+
'/hello': 'world',
368+
};
369+
vol.fromJSON(json);
370+
await new Promise((resolve, reject) => {
371+
vol
372+
.createReadStream('/hello')
373+
.on('data', () => null)
374+
.on('close', resolve)
375+
.on('end', () => {
376+
vol.reset();
377+
})
378+
.on('error', reject);
379+
});
380+
});
364381
});
365382
describe('.openSync(path, flags[, mode])', () => {
366383
const vol = new Volume();

‎src/volume.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -825,7 +825,9 @@ export class Volume implements FsCallbackApi, FsSynchronousApi {
825825

826826
close(fd: number, callback: TCallback<void>) {
827827
validateFd(fd);
828-
this.wrapAsync(this.closeSync, [fd], callback);
828+
const file = this.getFileByFdOrThrow(fd, 'close');
829+
// NOTE: not calling closeSync because we can reset in between close and closeSync
830+
this.wrapAsync(this.closeFile, [file], callback);
829831
}
830832

831833
private openFileOrGetById(id: TFileId, flagsNum: number, modeNum?: number): File {

0 commit comments

Comments
 (0)
Please sign in to comment.