From 464bd50e4efa081c7364c32c9e9e88809229ba21 Mon Sep 17 00:00:00 2001 From: Robert Nagy Date: Fri, 29 Dec 2023 20:44:40 +0100 Subject: [PATCH] EINVAL Refs: https://github.com/pinojs/sonic-boom/issues/189 --- index.js | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/index.js b/index.js index 7b20ab7..2218b7e 100644 --- a/index.js +++ b/index.js @@ -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) @@ -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 - cb(err) - }) + try { + fs.fsync(this.fd, (err) => { + this._flushPending = false + cb(err) + }) + } catch (err) { + cb(err) + } } else { this._flushPending = false cb() @@ -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