Skip to content

Race condition with hardware acceleration check #58

Description

@aptalca

I've been using stremio server on one server for a long time and it worked fine, auto detecting both qsv and vaapi.

But I just installed it on a new server with an Intel N150 and to my surprise, the hardware acceleration checks were failing to detect qsv and vaapi.

Some trial and error led to this discovery, which suggests a race condition in the hw accel check.

Here's the log from a newly started container:

hls executables located ->  {
  ffmpeg: '/usr/lib/jellyfin-ffmpeg/ffmpeg',
  ffsplit: null,
  ffprobe: '/usr/lib/jellyfin-ffmpeg/ffprobe'
}
Using app path -> /config
(node:1) [DEP0005] DeprecationWarning: Buffer() is deprecated due to security and usability issues. Please use the Buffer.alloc(), Buffer.allocUnsafe(), or Buffer.from() methods instead.
(Use `node --trace-deprecation ...` to show where the warning was created)
EngineFS server started at http://127.0.0.1:11470
EngineFS HTTPS endpoint at https://local.strem.io:12470

Then we open https://web.stremio.com and point it to our newly created server:

-> GET /casting
-> GET /device-info
hls-converter - Initiating tests for hardware accelerated transcoding support, possible options: qsv-linux,nvenc-linux,vaapi-renderD128
hls-converter - Testing video hw accel for profile: qsv-linux
-> GET /network-info
-> GET /settings
-> GET /hlsv2/11470-qsv-linux-video-hevc.mkv/video0.m3u8?mediaURL=http%3A%2F%2F127.0.0.1%3A11470%2Fsamples%2Fhevc.mkv&profile=qsv-linux&maxWidth=1200
-> GET /samples/hevc.mkv bytes=0-
-> GET /samples/hevc.mkv
Error [ERR_STREAM_PREMATURE_CLOSE]: Premature close
    at new NodeError (internal/errors.js:322:7)
    at Socket.onclose (internal/streams/end-of-stream.js:121:38)
    at Socket.emit (events.js:412:35)
    at Pipe.<anonymous> (net.js:686:12) {
  code: 'ERR_STREAM_PREMATURE_CLOSE'
}
-> GET /hlsv2/11470-qsv-linux-video-hevc.mkv/destroy
hls-converter 11470-qsv-linux-video-hevc.mkv has been requested to be destroyed
hls-converter 11470-qsv-linux-video-hevc.mkv destoyed
hls-converter - Tests failed for [video] hw accel profile: qsv-linux
hls-converter - Some tests failed for hw accel profile: qsv-linux
hls-converter - Testing video hw accel for profile: nvenc-linux
-> GET /hlsv2/11470-nvenc-linux-video-hevc.mkv/video0.m3u8?mediaURL=http%3A%2F%2F127.0.0.1%3A11470%2Fsamples%2Fhevc.mkv&profile=nvenc-linux&maxWidth=1200
hls-converter 11470-qsv-linux-video-hevc.mkv will be destroyed due to passing concurrency of 1
-> GET /samples/hevc.mkv
Error [ERR_STREAM_PREMATURE_CLOSE]: Premature close
    at new NodeError (internal/errors.js:322:7)
    at Socket.onclose (internal/streams/end-of-stream.js:121:38)
    at Socket.emit (events.js:412:35)
    at Pipe.<anonymous> (net.js:686:12) {
  code: 'ERR_STREAM_PREMATURE_CLOSE'
}
-> GET /hlsv2/11470-nvenc-linux-video-hevc.mkv/destroy
hls-converter 11470-nvenc-linux-video-hevc.mkv has been requested to be destroyed
hls-converter 11470-nvenc-linux-video-hevc.mkv destoyed
hls-converter - Tests failed for [video] hw accel profile: nvenc-linux
hls-converter - Some tests failed for hw accel profile: nvenc-linux
hls-converter - Testing video hw accel for profile: vaapi-renderD128
-> GET /hlsv2/11470-vaapi-renderD128-video-hevc.mkv/video0.m3u8?mediaURL=http%3A%2F%2F127.0.0.1%3A11470%2Fsamples%2Fhevc.mkv&profile=vaapi-renderD128&maxWidth=1200
hls-converter 11470-nvenc-linux-video-hevc.mkv will be destroyed due to passing concurrency of 1
-> GET /samples/hevc.mkv
Error [ERR_STREAM_PREMATURE_CLOSE]: Premature close
    at new NodeError (internal/errors.js:322:7)
    at Socket.onclose (internal/streams/end-of-stream.js:121:38)
    at Socket.emit (events.js:412:35)
    at Pipe.<anonymous> (net.js:686:12) {
  code: 'ERR_STREAM_PREMATURE_CLOSE'
}
-> GET /hlsv2/11470-vaapi-renderD128-video-hevc.mkv/destroy
hls-converter 11470-vaapi-renderD128-video-hevc.mkv has been requested to be destroyed
hls-converter 11470-vaapi-renderD128-video-hevc.mkv destoyed
hls-converter - Tests failed for [video] hw accel profile: vaapi-renderD128
hls-converter - Some tests failed for hw accel profile: vaapi-renderD128
hls-converter - Tests for hardware accelerated transcoding finished, no viable acceleration profiles detected

No viable profiles detected.

Then if I manually exec into the container and curl this address manually, I get the following output:

node@fb11cfbc227d:/stremio$ curl -L http://127.0.0.1:11470/hlsv2/11470-qsv-linux-video-hevc.mkv/video0.m3u8?mediaURL=http%3A%2F%2F127.0.0.1%3A11470%2Fsamples%2Fhevc.mkv&profile=qsv-linux&maxWidth=1200
[1] 33
[2] 34
node@fb11cfbc227d:/stremio$ #EXTM3U
#EXT-X-VERSION:7
#EXT-X-TARGETDURATION:1
#EXT-X-MEDIA-SEQUENCE:1
#EXT-X-PLAYLIST-TYPE:VOD
#EXT-X-MAP:URI="video0/init.mp4?mediaURL=http%3A%2F%2F127.0.0.1%3A11470%2Fsamples%2Fhevc.mkv"
#EXTINF:0.200033,
video0/segment1.m4s?mediaURL=http%3A%2F%2F127.0.0.1%3A11470%2Fsamples%2Fhevc.mkv
#EXT-X-ENDLIST
[1]-  Done                    curl -L http://127.0.0.1:11470/hlsv2/11470-qsv-linux-video-hevc.mkv/video0.m3u8?mediaURL=http%3A%2F%2F127.0.0.1%3A11470%2Fsamples%2Fhevc.mkv
[2]+  Done                    profile=qsv-linux

and the container logs shows:

hls-converter 11470-vaapi-renderD128-video-hevc.mkv is inactive, destroying it
hls-converter 11470-vaapi-renderD128-video-hevc.mkv destoyed
-> GET /hlsv2/11470-qsv-linux-video-hevc.mkv/video0.m3u8?mediaURL=http%3A%2F%2F127.0.0.1%3A11470%2Fsamples%2Fhevc.mkv
-> GET /samples/hevc.mkv
-> GET /samples/hevc.mkv bytes=0-

Then we reconnect the web app and here are the logs:

-> GET /network-info
-> GET /casting
-> GET /settings
-> GET /device-info
hls-converter - Initiating tests for hardware accelerated transcoding support, possible options: qsv-linux,nvenc-linux,vaapi-renderD128
hls-converter - Testing video hw accel for profile: qsv-linux
-> GET /hlsv2/11470-qsv-linux-video-hevc.mkv/video0.m3u8?mediaURL=http%3A%2F%2F127.0.0.1%3A11470%2Fsamples%2Fhevc.mkv&profile=qsv-linux&maxWidth=1200
-> GET /hlsv2/11470-qsv-linux-video-hevc.mkv/destroy
hls-converter 11470-qsv-linux-video-hevc.mkv has been requested to be destroyed
hls-converter 11470-qsv-linux-video-hevc.mkv destoyed
hls-converter - Tests passed for [video] hw accel profile: qsv-linux
hls-converter - All tests passed for hw accel profile: qsv-linux
hls-converter - Testing video hw accel for profile: nvenc-linux
-> GET /hlsv2/11470-nvenc-linux-video-hevc.mkv/video0.m3u8?mediaURL=http%3A%2F%2F127.0.0.1%3A11470%2Fsamples%2Fhevc.mkv&profile=nvenc-linux&maxWidth=1200
hls-converter 11470-qsv-linux-video-hevc.mkv will be destroyed due to passing concurrency of 1
-> GET /samples/hevc.mkv
Error [ERR_STREAM_PREMATURE_CLOSE]: Premature close
    at new NodeError (internal/errors.js:322:7)
    at Socket.onclose (internal/streams/end-of-stream.js:121:38)
    at Socket.emit (events.js:412:35)
    at Pipe.<anonymous> (net.js:686:12) {
  code: 'ERR_STREAM_PREMATURE_CLOSE'
}
-> GET /hlsv2/11470-nvenc-linux-video-hevc.mkv/destroy
hls-converter 11470-nvenc-linux-video-hevc.mkv has been requested to be destroyed
hls-converter 11470-nvenc-linux-video-hevc.mkv destoyed
hls-converter - Tests failed for [video] hw accel profile: nvenc-linux
hls-converter - Some tests failed for hw accel profile: nvenc-linux
hls-converter - Testing video hw accel for profile: vaapi-renderD128
-> GET /hlsv2/11470-vaapi-renderD128-video-hevc.mkv/video0.m3u8?mediaURL=http%3A%2F%2F127.0.0.1%3A11470%2Fsamples%2Fhevc.mkv&profile=vaapi-renderD128&maxWidth=1200
hls-converter 11470-nvenc-linux-video-hevc.mkv will be destroyed due to passing concurrency of 1
-> GET /samples/hevc.mkv
Error [ERR_STREAM_PREMATURE_CLOSE]: Premature close
    at new NodeError (internal/errors.js:322:7)
    at Socket.onclose (internal/streams/end-of-stream.js:121:38)
    at Socket.emit (events.js:412:35)
    at Pipe.<anonymous> (net.js:686:12) {
  code: 'ERR_STREAM_PREMATURE_CLOSE'
}
-> GET /hlsv2/11470-vaapi-renderD128-video-hevc.mkv/destroy
hls-converter 11470-vaapi-renderD128-video-hevc.mkv has been requested to be destroyed
hls-converter 11470-vaapi-renderD128-video-hevc.mkv destoyed
hls-converter - Tests failed for [video] hw accel profile: vaapi-renderD128
hls-converter - Some tests failed for hw accel profile: vaapi-renderD128
hls-converter - Tests for hardware accelerated transcoding finished, supported acceleration profiles: qsv-linux
-> POST /settings

Viola, qsv detected (but not vaapi).

So something funny is definitely going on, most likely a race condition.

PS. The container was created via the following compose:

  stremio:
    image: stremio/server
    container_name: stremio
    devices:
      - /dev/dri:/dev/dri
    environment:
      - TZ=America/New_York
      - APP_PATH=/config
      - NO_CORS=1
    volumes:
      - /home/aptalca/appdata/stremio:/config
    restart: unless-stopped

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions