Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

EINVAL #190

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
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
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