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

Skip throws Error [ERR_STREAM_PREMATURE_CLOSE] #1570

Closed
Cyopn opened this issue Feb 12, 2023 · 9 comments · Fixed by #1513
Closed

Skip throws Error [ERR_STREAM_PREMATURE_CLOSE] #1570

Cyopn opened this issue Feb 12, 2023 · 9 comments · Fixed by #1513
Labels
bug Something isn't working develop:resolved

Comments

@Cyopn
Copy link

Cyopn commented Feb 12, 2023

It happens when i use skip and stop, throws the exception, but the queue doesnt ends, rather it restarts but in another order.
The error picks them up from the event Player.on("error").

Full exception:
Error [ERR_STREAM_PREMATURE_CLOSE]: Premature close
at new NodeError (node:internal/errors:387:5)
at PCMResampler.onclose (node:internal/streams/end-of-stream:140:30)
at PCMResampler.emit (node:events:525:35)
at emitCloseNT (node:internal/streams/destroy:138:10)
at processTicksAndRejections (node:internal/process/task_queues:82:21) {
code: 'ERR_STREAM_PREMATURE_CLOSE'
}
discord-player: dev

Thanks.

@Cyopn Cyopn added the bug Something isn't working label Feb 12, 2023
@twlite
Copy link
Collaborator

twlite commented Feb 12, 2023

You can ignore this error, it is caused by the usage of pipeline. I will fix this

@Victorcassiano
Copy link

when I use the command the music stops and after a few seconds the bot disconnects.
Another error is when, sometimes, I use .addTrack() sometimes the song jumps to the second one that was added

@twlite twlite linked a pull request Mar 2, 2023 that will close this issue
@nerblock
Copy link

I'm getting this error too using the latest version from npm:

[2023-03-25 13:10:01] [ERROR] Error [ERR_STREAM_PREMATURE_CLOSE]: Premature close
    at new NodeError (node:internal/errors:393:5)
    at Encoder.<anonymous> (node:internal/streams/pipeline:352:14)
    at Encoder.emit (node:events:525:35)
    at Encoder.emit (node:domain:489:12)
    at emitCloseNT (node:internal/streams/destroy:132:10)
    at processTicksAndRejections (node:internal/process/task_queues:81:21) {
  code: 'ERR_STREAM_PREMATURE_CLOSE'
}

The solution is to ignore uncaught exceptions but then pm2 can't restart the process when something else breaks. Can I ask when will the fix be included in npm?

@twlite
Copy link
Collaborator

twlite commented Mar 25, 2023

This fix is already included in discord-player part (handled on dsp filters pipeline). You might be getting this error elsewhere because if it was from discord-player, the error event would have caught it.

Edit: as per your stacktrace, it seems to be coming from Encoder class, which does not exist in discord-player

@nerblock
Copy link

My trace is similar to the one in the first comment. Only difference I can see is the PCMResampler class, which is replaced with Encoder in my trace. The exception occurs when I queue.delete() or player.destroy() while playing a youtube video. Do you think my problem is unrelated to this bug?

@twlite
Copy link
Collaborator

twlite commented Mar 25, 2023

My trace is similar to the one in the first comment. Only difference I can see is the PCMResampler class, which is replaced with Encoder in my trace. The exception occurs when I queue.delete() or player.destroy() while playing a youtube video. Do you think my problem is unrelated to this bug?

The original error of this issue came from

if (!err.message.includes('ERR_STREAM_PREMATURE_CLOSE')) this.onError(err);
which is handled in current version.

It could be due to a fault in npm install causing some dependencies to break, you can try removing node_modules and your lockfile, executing npm cache clean --force and finally running npm install to see if that is the case.

@nerblock
Copy link

Unfortunately the problem persists after removing node_modules and cleaning the cache. I've found Encoder in prism-media:

function loadOpus(refresh = false) {
  if (Opus.Encoder && !refresh) return Opus;

  Opus = loader.require([
    ['@discordjs/opus', opus => ({ Encoder: opus.OpusEncoder })],
    ['node-opus', opus => ({ Encoder: opus.OpusEncoder })],
    ['opusscript', opus => ({ Encoder: opus })],
  ]);
  return Opus;
}

@nerblock
Copy link

The original error of this issue came from

if (!err.message.includes('ERR_STREAM_PREMATURE_CLOSE')) this.onError(err);

I added console logging to this file and can confirm the exception comes from some other place.

@nerblock
Copy link

Well, I gave up and just added filtering to the uncaught exception handler. Not pretty but works.

process.on("uncaughtException", function (err) {
  if (!err.stack?.includes("ERR_STREAM_PREMATURE_CLOSE")) {
    console.error(err.stack);
    exitHandler.bind(null, { exit: true, signal: "uncaughtException" });
  }
});

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working develop:resolved
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants