From eaf2e747eeb2026e70a0cef67c50505aae25490a 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 | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/index.js b/index.js index 7b20ab7..1e2e0bb 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 + 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