Skip to content

Commit

Permalink
EINVAL
Browse files Browse the repository at this point in the history
  • Loading branch information
ronag committed Dec 29, 2023
1 parent 95f55eb commit eaf2e74
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 @@ -342,10 +343,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 @@ -634,7 +639,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 eaf2e74

Please sign in to comment.