Skip to content

Error [ERR_IPC_DISCONNECTED]: IPC channel is already disconnected #3

@OllyNural

Description

@OllyNural

When running this against a wav file, converting to JSON (using the code from the example in /examples) I receive this error:

Error [ERR_IPC_DISCONNECTED]: IPC channel is already disconnected
    at process.target.disconnect (internal/child_process.js:861:26)
    at checkWaitingCount (internal/cluster/child.js:209:17)
    at Worker._disconnect (internal/cluster/child.js:226:3)
    at Worker.onmessage (internal/cluster/child.js:52:19)
    at process.onInternalMessage (internal/cluster/utils.js:47:8)
    at process.emit (events.js:327:22)
    at emit (internal/child_process.js:906:12)
    at processTicksAndRejections (internal/process/task_queues.js:85:21)
Emitted 'error' event on Worker instance at:
    at process.<anonymous> (internal/cluster/worker.js:29:12)
    at process.emit (events.js:315:20)
    at process.target.disconnect (internal/child_process.js:861:12)
    at checkWaitingCount (internal/cluster/child.js:209:17)
    [... events.js:292
      throw er; // Unhandled 'error' event
      ^

Code:

const convertAudioFile = (audioFileName) => {
    const fileName = audioFileName.split('.')[0]
    var spectro = new Spectro()
    var audioFile = fs.createReadStream(`${__dirname}/data/wav/${fileName}.wav`, { start: 44 }) // Note: The first 44 bytes are the wav-header

    return new Promise((res, rej) => {
        // The file stream can simply be piped into the Spectro instance
        audioFile.pipe(spectro)

        // Check when the file stream completed
        var fileRead = false
        audioFile.on('end', () => {
            fileRead = true
        })

        // The data event can be used to work with recently processed data from the workers
        spectro.on('data', (err, frame) => {
            if (err) rej(err)
            // frame contains an index of the processed frame and a data section with the processed data
        })

        try {
            spectro.on('end', (err, data) => {
                if (err) rej(err)
                // The 'end' event always fires when spectro has reached the end of the currently processable data
                // Therefore we should check if the file was read completely before using the data
                if (fileRead !== true) return
                try {
                    spectro.stop()
                } catch (e) {
                    console.log(e)
                }
                
                // const max = Spectro.maxApplitude(data)
                // const min = Spectro.minApplitude(data)
                // console.log(`Max amplitude is ${max}, min amplitude is ${min}`)
                fs.writeFileSync(`${__dirname}/data/json/${fileName}.json`, JSON.stringify(data), 'utf-8');
                res()
            })
        } catch (e) {
            console.log(e)
            rej(e)
        }
    })
}

(I've added try/catch, and promises, but it was failing without those)

After a bit of Googling, the error seems to be related to trying to stop the process when it's already stopped. I've tried adding:

  if (!worker.exitedAfterDisconnect) {
    worker.disconnect()
  }

In the Spectrogram.prototype.stop = function()

However this didn't work, tested locally when editing my node_modules.

Thoughts?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions