Skip to content

Commit

Permalink
EINVAL (#190)
Browse files Browse the repository at this point in the history
Refs: #189
  • Loading branch information
ronag authored Oct 15, 2024
1 parent 1b992ac commit 15f1c32
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 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
const kEmptyBuffer = Buffer.allocUnsafe(0)
Expand Down Expand Up @@ -364,10 +365,14 @@ function callFlushCallbackOnDrain (cb) {
const onDrain = () => {
// only if _fsync is false to avoid double fsync
if (!this._fsync) {
fs.fsync(this.fd, (err) => {
this._flushPending = false
try {
fs.fsync(this.fd, (err) => {
this._flushPending = false
cb(err)
})
} catch (err) {
cb(err)
})
}
} else {
this._flushPending = false
cb()
Expand Down Expand Up @@ -670,7 +675,11 @@ function actualClose (sonic) {
sonic._bufs = []
sonic._lens = []

fs.fsync(sonic.fd, closeWrapped)
assert(typeof sonic.fd === 'number', `sonic.fd must be a number, got ${typeof sonic.fd}`)
try {
fs.fsync(sonic.fd, closeWrapped)
} catch {
}

function closeWrapped () {
// We skip errors in fsync
Expand Down

0 comments on commit 15f1c32

Please sign in to comment.