SamuelScheit / puppeteer-stream

A Library for puppeteer to retrieve audio and/or video streams
MIT License
333 stars 105 forks source link

Shutdown is taking more than 5 seconds #131

Closed RobertoUa closed 10 months ago

RobertoUa commented 10 months ago

The issue is with this setTimeout. Please add .unref() so that exit is not delayed. Browser and ffmpeg is already closed so there no need to wait for this https://github.com/SamuelScheit/puppeteer-stream/blob/main/src/PuppeteerStream.ts#L186

SamuelScheit commented 10 months ago

this is required, because some packets might be delayed and take some time to get delivered, the timeout ensures that these packets arrive and the full length of the video is recorded.

RobertoUa commented 10 months ago

at least make the timeout configurable

RobertoUa commented 10 months ago

and you can also check if socket is already closed before creating timeout

SamuelScheit commented 10 months ago

Done in puppeteer-stream@3.0.7:

const stream = getStream(page, { 
  streamConfig: {
    closeTimeout: 5000
  }
})
RobertoUa commented 10 months ago

btw, since we're talking about script closing, I sometimes get (Runtime.callFunctionOn): Target closed when extension.evaluate((index) => STOP_RECORDING(index), index) is run. I belive you can a catch there.

RobertoUa commented 10 months ago

this is great! thank you so much! Especially for the fastest response ever! The requirement of my app is to shutdown as fast as possible when everything is processed (ffmpeg was already closed at that point and video produced)

RobertoUa commented 10 months ago

can you please catch errors in extension.evaluate((index) => STOP_RECORDING(index), index) I get this most of the time

uncaughtException: Protocol error (Runtime.callFunctionOn): Target closed
TargetCloseError: Protocol error (Runtime.callFunctionOn): Target closed