Open ronag opened 3 years ago
I think actualClose
just needs a:
if (sonic._writing) {
sonic.once('drain', actualClose.bind(null, sonic))
return
}
Did you see this happening?
Did you see this happening?
Nope. Just based on review of the code. These kind of undefined behaviors are very to actually notice in practice.
This is protected and it can't happen.
I'm not sure I agree. It only waits for it to be ready not to finish pending async writes (writing).
If you add the following assertion then the test suite will fail:
index 45bf86d..2d4f8a2 100644
--- a/index.js
+++ b/index.js
@@ -8,6 +8,7 @@ const path = require('path')
const BUSY_WRITE_TIMEOUT = 100
const sleep = require('atomic-sleep')
+const assert = require('assert')
// 16 MB - magic number
// This constant ensures that SonicBoom only needs
@@ -368,6 +369,7 @@ function actualClose (sonic) {
sonic.once('ready', actualClose.bind(null, sonic))
return
}
+ assert(!sonic._writing)
// TODO write a test to check if we are not leaking fds
fs.close(sonic.fd, (err) => {
if (err) {
ah sorry! I ready 'drain'
for 'ready'
.
In practice I have not seen this being a problem - we have done extensive testing and we did not get corrupt data.
actualClose can close fd while writing causing undefined behavior.