Skip to content

Commit

Permalink
fix: don't close while writing
Browse files Browse the repository at this point in the history
Fixes: #98
  • Loading branch information
ronag committed Aug 29, 2021
1 parent ad88efd commit 71c73ad
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions 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,11 @@ function actualClose (sonic) {
sonic.once('ready', actualClose.bind(null, sonic))
return
}
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 Down

0 comments on commit 71c73ad

Please sign in to comment.