diff --git a/.github/workflows/mediasoup-worker-fuzzer.yaml b/.github/workflows/mediasoup-worker-fuzzer.yaml index 5f4e5d953e..211754342f 100644 --- a/.github/workflows/mediasoup-worker-fuzzer.yaml +++ b/.github/workflows/mediasoup-worker-fuzzer.yaml @@ -37,4 +37,6 @@ jobs: - name: invoke -r worker fuzzer run: invoke -r worker fuzzer - # We don't run mediasoup-worker-fuzzer (maybe in the future). + # Run mediasoup-worker-fuzzer for 5 minutes. + - name: run-fuzzer.sh 300 + run: cd worker && ./scripts/run-fuzzer.sh 300 diff --git a/worker/Dockerfile b/worker/Dockerfile index 64ae430df2..674291f118 100644 --- a/worker/Dockerfile +++ b/worker/Dockerfile @@ -28,6 +28,9 @@ ENV CXX="clang++" ENV MEDIASOUP_LOCAL_DEV="true" ENV KEEP_BUILD_ARTIFACTS="1" +# Disable liburing due to this bug: +# https://github.com/versatica/mediasoup/issues/1334 +ENV MESON_ARGS="-Dms_disable_liburing=true" WORKDIR /mediasoup diff --git a/worker/Dockerfile.alpine b/worker/Dockerfile.alpine index 68cf11664d..04689b61f0 100644 --- a/worker/Dockerfile.alpine +++ b/worker/Dockerfile.alpine @@ -11,6 +11,9 @@ ENV CXX="g++" ENV MEDIASOUP_LOCAL_DEV="true" ENV KEEP_BUILD_ARTIFACTS="1" +# Disable liburing due to this bug: +# https://github.com/versatica/mediasoup/issues/1334 +ENV MESON_ARGS="-Dms_disable_liburing=true" WORKDIR /mediasoup diff --git a/worker/scripts/run-fuzzer.sh b/worker/scripts/run-fuzzer.sh new file mode 100755 index 0000000000..bc9c5321b6 --- /dev/null +++ b/worker/scripts/run-fuzzer.sh @@ -0,0 +1,38 @@ +#!/usr/bin/env bash + +WORKER_PWD=${PWD} +DURATION_SEC=$1 + +current_dir_name=${WORKER_PWD##*/} +if [ "${current_dir_name}" != "worker" ] ; then + echo "run-fuzzer.sh [ERROR] $(basename $0) must be called from mediasoup/worker directory" >&2 + exit 1 +fi + +if [ "$#" -eq 0 ] ; then + echo "run-fuzzer.sh [ERROR] duration (in seconds) must be fiven as argument" >&2 + exit 1 +fi + +invoke fuzzer-run-all & + +MEDIASOUP_WORKER_FUZZER_PID=$! + +i=${DURATION_SEC} + +until [ ${i} -eq 0 ] +do + echo "run-fuzzer.sh [INFO] ${i} seconds left" + if ! kill -0 ${MEDIASOUP_WORKER_FUZZER_PID} &> /dev/null ; then + echo "run-fuzzer.sh [ERROR] mediasoup-worker-fuzzer died" >&2 + exit 1 + else + ((i=i-1)) + sleep 1 + fi +done + +echo "run-fuzzer.sh [INFO] mediasoup-worker-fuzzer is still running after given ${DURATION_SEC} seconds so no fuzzer issues so far" + +kill -SIGTERM ${MEDIASOUP_WORKER_FUZZER_PID} &> /dev/null +exit 0 diff --git a/worker/tasks.py b/worker/tasks.py index a99f74cf5c..728e7cf962 100644 --- a/worker/tasks.py +++ b/worker/tasks.py @@ -23,7 +23,7 @@ import inspect; import shutil; # We import this from a custom location and pylint doesn't know. -from invoke import task; # pylint: disable=import-error +from invoke import task, call; # pylint: disable=import-error MEDIASOUP_BUILDTYPE = os.getenv('MEDIASOUP_BUILDTYPE') or 'Release'; WORKER_DIR = os.path.dirname(os.path.abspath( @@ -135,14 +135,14 @@ def meson_ninja(ctx): @task(pre=[meson_ninja]) -def setup(ctx): +def setup(ctx, meson_args=MESON_ARGS): """ Run meson setup """ if MEDIASOUP_BUILDTYPE == 'Release': with ctx.cd(f'"{WORKER_DIR}"'): ctx.run( - f'"{MESON}" setup --prefix "{MEDIASOUP_INSTALL_DIR}" --bindir "" --libdir "" --buildtype release -Db_ndebug=true {MESON_ARGS} "{BUILD_DIR}"', + f'"{MESON}" setup --prefix "{MEDIASOUP_INSTALL_DIR}" --bindir "" --libdir "" --buildtype release -Db_ndebug=true {meson_args} "{BUILD_DIR}"', echo=True, pty=PTY_SUPPORTED, shell=SHELL @@ -150,7 +150,7 @@ def setup(ctx): elif MEDIASOUP_BUILDTYPE == 'Debug': with ctx.cd(f'"{WORKER_DIR}"'): ctx.run( - f'"{MESON}" setup --prefix "{MEDIASOUP_INSTALL_DIR}" --bindir "" --libdir "" --buildtype debug {MESON_ARGS} "{BUILD_DIR}"', + f'"{MESON}" setup --prefix "{MEDIASOUP_INSTALL_DIR}" --bindir "" --libdir "" --buildtype debug {meson_args} "{BUILD_DIR}"', echo=True, pty=PTY_SUPPORTED, shell=SHELL @@ -158,7 +158,7 @@ def setup(ctx): else: with ctx.cd(f'"{WORKER_DIR}"'): ctx.run( - f'"{MESON}" setup --prefix "{MEDIASOUP_INSTALL_DIR}" --bindir "" --libdir "" --buildtype {MEDIASOUP_BUILDTYPE} -Db_ndebug=if-release {MESON_ARGS} "{BUILD_DIR}"', + f'"{MESON}" setup --prefix "{MEDIASOUP_INSTALL_DIR}" --bindir "" --libdir "" --buildtype {MEDIASOUP_BUILDTYPE} -Db_ndebug=if-release {meson_args} "{BUILD_DIR}"', echo=True, pty=PTY_SUPPORTED, shell=SHELL @@ -464,11 +464,15 @@ def tidy(ctx): ); -@task(pre=[setup, flatc]) +@task(pre=[call(setup, meson_args=MESON_ARGS + ' -Db_sanitize=address'), flatc]) def fuzzer(ctx): """ Build the mediasoup-worker-fuzzer binary (which uses libFuzzer) """ + + # NOTE: We need to pass '-Db_sanitize=address' to enable fuzzer in all Meson + # subprojects, so we pass it to the setup() task. + with ctx.cd(f'"{WORKER_DIR}"'): ctx.run( f'"{MESON}" compile -C "{BUILD_DIR}" -j {NUM_CORES} mediasoup-worker-fuzzer',