canyanio / janus-gateway-docker

Docker image for the Janus WebRTC Server
Other
160 stars 64 forks source link

libwebsockets issue with unlimitied file descriptors #22

Open goalves opened 2 years ago

goalves commented 2 years ago
...
Loading transport plugin 'libjanus_websockets.so'...
libwebsockets logging: 2047
[libwebsockets][INFO] Initial logging level 2047
[libwebsockets][INFO] Libwebsockets version: 4.0.20 unknown-build-hash
[libwebsockets][INFO] IPV6 compiled in and enabled
[libwebsockets][INFO]  LWS_DEF_HEADER_LEN    : 4096
[libwebsockets][INFO]  LWS_MAX_SMP           : 1
[libwebsockets][INFO]  sizeof (*info)        : 704
[libwebsockets][INFO]  SYSTEM_RANDOM_FILEPATH: '/dev/urandom'
[libwebsockets][INFO]  HTTP2 support         : available
[libwebsockets][DEBUG] _realloc: size 9000: context
[libwebsockets][INFO] context created
[libwebsockets][INFO] Using event loop: poll
[libwebsockets][INFO] Default ALPN advertisment: h2,http/1.1
[libwebsockets][INFO]  default timeout (secs): 20
[libwebsockets][INFO]  Threads: 1 each 1073741816 fds
[libwebsockets][INFO]  mem: context:          8096 B (4000 ctx + (1 thr x 4096))
[libwebsockets][INFO]  mem: http hdr size:   (4096 + 976), max count 1073741816
[libwebsockets][DEBUG] _realloc: size 18446744073709551552: fds table
[libwebsockets][ERR] OOM allocating 1073741816 fds
[libwebsockets][INFO] lws_context_destroy: ctx 0x55ca479e0930
[libwebsockets][DEBUG] _lws_state_transition: (null): changed 0 '0' -> 11 '0'
[libwebsockets][INFO] lws_pt_destroy: pt destroyed
[libwebsockets][INFO] lws_context_destroy2: ctx 0x55ca479e0930
[libwebsockets][DEBUG] 0x7f81d81a4810: post vh listl
[libwebsockets][DEBUG] 0x7f81d81a4810: post pdl
[libwebsockets][ERR] ZERO RANDOM FD
[libwebsockets][DEBUG] 0x7f81d81a4810: baggage
[libwebsockets][DEBUG] 0x7f81d81a4810: post dc2
[libwebsockets][INFO] lws_system_blob_destroy: blob 0x55ca479e09f0
[libwebsockets][INFO] lws_system_blob_destroy: blob 0x55ca479e0a08
[libwebsockets][INFO] lws_system_blob_destroy: blob 0x55ca479e0a20
[libwebsockets][INFO] lws_system_blob_destroy: blob 0x55ca479e0a38
[libwebsockets][INFO] lws_system_blob_destroy: blob 0x55ca479e0a50
[libwebsockets][INFO] lws_system_blob_destroy: blob 0x55ca479e0a68
[libwebsockets][INFO] lws_system_blob_destroy: blob 0x55ca479e0a80
[libwebsockets][INFO] lws_system_blob_destroy: blob 0x55ca479e0a98
[libwebsockets][INFO] lws_context_destroy3: ctx 0x55ca479e0930 freed
[ERR] [transports/janus_websockets.c:janus_websockets_init:577] Error creating libwebsockets context...

The important line is: [libwebsockets][ERR] OOM allocating 1073741816 fds.

This happens if the ulimit is set to infinity on systemd for the docker service (or cgroups/whatever you are using) and because of how the code is written here.

I had to change this on my machine (or in the docker-compose file by setting ulimit to a sane value) but I suppose it is not really straightforward to debug, do you think it is valuable to add something in the README or anywhere regarding this?

version: "2"
services:
  janus:
    image: canyan/janus-gateway:latest
    ports:
      - 8188:8188
      - 8088:8088
      - 8089:8089
      - 8889:8889
      - 8000:8000
      - 7088:7088
      - 7089:7089
    ulimits:
      nofile:
        soft: 200000
        hard: 200000