Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ const EventEmitter = require('events')
const inherits = require('util').inherits
const path = require('path')
const sleep = require('atomic-sleep')
const assert = require('assert')

const BUSY_WRITE_TIMEOUT = 100

Expand Down Expand Up @@ -374,6 +375,15 @@ function actualClose (sonic) {
sonic.once('ready', actualClose.bind(null, sonic))
return
}

sonic.destroyed = true

if (sonic._writing) {
sonic.once('drain', 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) {
Expand All @@ -386,7 +396,6 @@ function actualClose (sonic) {
}
sonic.emit('close')
})
sonic.destroyed = true
sonic._bufs = []
}

Expand Down