MatrixAI / js-encryptedfs

Encrypted Filesystem for TypeScript/JavaScript Applications
https://polykey.com
Apache License 2.0
10 stars 3 forks source link

Streams don't seem to emit the close event #72

Closed CMCDragonkai closed 1 year ago

CMCDragonkai commented 1 year ago

Describe the bug

Some testing from #71 show that streams are not emitting the close event after ending.

Because streams have auto close enabled, after the finish event, a close event should be emitted.

s = fs.createWriteStream('./tmp/s');
s.write('abc');
s.write('abc');
s.on('finish', () => { console.log('emitted finish'); });
s.on('close', () => { console.log('emitted close'); });
s.end();

In the above, a regular FS stream does end up emitting the close event.

However in our streams, this is not occurring. Not sure why.

It seems calling destroy() does not result in a close event.

This may be an upstream readable-stream bug. But the latest readable-stream is significantly different. We can try upgrading.

New tests should be written for these streams to check for the close event.

To Reproduce

  1. Do the above but with EFS

Expected behavior

Should say:

emitted finish
emitted close
tegefaulkes commented 1 year ago

I can't recreate this bug. Using the snippet above I end up with the expected behaviour. I did have to make 1 change however. Using the path './tmp/s' resulted in a error event with the error ErrorEncryptedFSError: ENOENT: no such file or directory, ./tmp/s, a close event but no finish event. Maybe that was the problem?

Doing the same thing with the FS but using a path that can't be created results in the same behaviour where we get the ENOENT error event, a close event and no finish event.

Using a path that can exist for the EFS results in the expected behaviour.

In any case I'll mark this as resolved when #74 merges.

CMCDragonkai commented 1 year ago

Fixed by #74.