centricular / gstcefsrc

A simple gstreamer wrapper around Chromium Embedded Framework
86 stars 45 forks source link

Cef Segmentation fault #72

Open reinismu opened 1 year ago

reinismu commented 1 year ago

I have been running cefsrc in docker for a while now. Everything was fine until recently I updated docker images and it segfaults :( I assume issue is in this repo or https://github.com/restreamio/docker-gstreamer not sure.

Command to test

Xvfb :0 -screen 0 1920x1080x24 &

export GST_DEBUG=5
export GST_PLUGIN_PATH=/usr/cef:$GST_PLUGIN_PATH
export DISPLAY=:0

gst-launch-1.0 -e cefsrc url=https://soundcloud.com/platform/sama num-buffers=135000 gpu=false do-timestamp=true log-severity=1 ! \
    video/x-raw,width=1920,height=1080,framerate=50/1 ! cefdemux name=demux ! \
    queue max-size-bytes=4294967295 max-size-buffers=5000 max-size-time=18446744073709551615 ! \
    videoconvert ! x264enc ! mp4mux ! filesink location=output.mp4
ARG GST_PLUGINS_RS_TAG=main

FROM catthehacker/ubuntu:rust-22.04 as builder

# https://ryandaniels.ca/blog/docker-dockerfile-arg-from-arg-trouble/
ARG GST_PLUGINS_RS_TAG

WORKDIR /usr/src/gst-plugins-rs

ENV DEST_DIR /opt/gst-plugins-rs
ENV CARGO_PROFILE_RELEASE_DEBUG false

RUN apt update \
    && apt install -yq --no-install-recommends \
    libgstreamer-plugins-base1.0-dev \
    libgstreamer1.0-dev \
        libcsound64-dev \
    libclang-11-dev \
    libpango1.0-dev  \
    libdav1d-dev  
    # libgtk-4-dev # Only in bookworm

RUN git clone -c advice.detachedHead=false \
    --branch ${GST_PLUGINS_RS_TAG} \
    --single-branch https://github.com/sdroege/gst-plugin-rs \
    /usr/src/gst-plugins-rs

RUN export CSOUND_LIB_DIR="/usr/lib/$(uname -m)-linux-gnu" && \
    export PLUGINS_DIR=$(pkg-config --variable=pluginsdir gstreamer-1.0) && \
    export SO_SUFFIX=so && \
    cargo build --release  \
   --package gst-plugin-png \
    &&  \
    install -v -d ${DEST_DIR}/${PLUGINS_DIR} && \
    install -v -m 755 target/release/*.${SO_SUFFIX} ${DEST_DIR}${PLUGINS_DIR}

from restreamio/gstreamer:x86_64-latest-prod

COPY --from=builder /opt/gst-plugins-rs/ /

WORKDIR /usr/recorder

RUN apt update && \
    apt install -yq --no-install-recommends curl xvfb && \
    curl -s https://deb.nodesource.com/setup_16.x | bash && \
    apt-get install -y nodejs

ENV CEFSRC_PLUGIN_DIR /usr/cef

COPY . .

CMD ./run.sh
#!/bin/bash
export DISPLAY=:0

while :
do
    Xvfb :0 -screen 0 1920x1080x24
    echo "Xvfb has Crashed"
    sleep 1
done &

npm start

Debug log

0:00:00.561307153    12 0x55eee5cffb00 INFO                  cefsrc gstcefsrc.cc:713:run_cef: Initializing CEF
[0505/140854.168528:VERBOSE1:cdm_registration.cc(189)] Widevine enabled but no library found
[0505/140854.168530:VERBOSE1:cdm_registration.cc(189)] Widevine enabled but no library found
[0505/140854.168578:INFO:cpu_info.cc(53)] Available number of cores: 32
[0505/140854.168582:INFO:cpu_info.cc(53)] Available number of cores: 32
[0505/140854.168588:VERBOSE1:zygote_main_linux.cc(218)] ZygoteMain: initializing 0 fork delegates
[0505/140854.168586:VERBOSE1:zygote_main_linux.cc(218)] ZygoteMain: initializing 0 fork delegates
[0505/140854.172348:VERBOSE1:pref_proxy_config_tracker_impl.cc(187)] 0x7f8a08019d40: set chrome proxy config service to 0x7f8a08050180
[0505/140854.172524:VERBOSE1:cdm_registration.cc(189)] Widevine enabled but no library found
[0505/140854.173899:VERBOSE1:pulse_util.cc(236)] Failed to connect to the context.  Error: Connection refused
[0505/140854.173916:WARNING:audio_manager_linux.cc(60)] Falling back to ALSA for audio output. PulseAudio is not available or could not be initialized.
[0505/140854.173955:VERBOSE1:webrtc_internals.cc(120)] Could not get the download directory.
[0505/140854.174124:VERBOSE1:media_stream_manager.cc(1065)] MSM::InitializeMaybeAsync([this=0x7f8a08003990])
[0505/140854.174137:VERBOSE1:media_stream_manager.cc(1065)] MDM::MediaDevicesManager()
[0505/140854.174140:VERBOSE1:media_stream_manager.cc(1065)] MSM::MediaStreamManager([this=0x7f8a08003990]))
[0505/140854.175577:VERBOSE1:first_party_sets_handler_impl.cc(432)] Empty path. Failed loading serialized First-Party Sets file.
[0505/140854.175579:VERBOSE1:component_installer.cc(285)] StartRegistration for Widevine Content Decryption Module
[0505/140854.175800:VERBOSE1:component_installer.cc(441)] FinishRegistration for Widevine Content Decryption Module
[0505/140854.175815:VERBOSE1:component_updater_service.cc(131)] CrxUpdateService starting up. First update attempt will take place in 60 seconds. Next update attempt will take place in 18000 seconds. 
[0505/140854.177038:VERBOSE1:key_storage_util_linux.cc(54)] Password storage detected desktop environment: (unknown)
[0505/140854.177062:VERBOSE1:key_storage_linux.cc(123)] Selected backend for OSCrypt: BASIC_TEXT
[0505/140854.177068:VERBOSE1:key_storage_linux.cc(143)] OSCrypt did not initialize a backend.
[0505/140854.177137:VERBOSE1:pref_proxy_config_tracker_impl.cc(187)] 0x7f8a081748f0: set chrome proxy config service to 0x7f8a0816ea90
libva error: vaGetDriverNameByIndex() failed with unknown libva error, driver_name = (null)
[0100/000000.180773:VERBOSE1:vaapi_wrapper.cc(844)] InitializeVaDriver_Locked(): vaInitialize failed: unknown libva error
Segmentation fault (core dumped)
root@1937c1edc00c:/usr/recorder# [0100/000000.453051:WARNING:sandbox_linux.cc(380)] InitializeSandbox() called with multiple threads in process gpu-process.
MathieuDuponchelle commented 1 year ago

a stacktrace would help :stuck_out_tongue:

reinismu commented 1 year ago

You are right. Haven't run into seg faults in a while :)

0:00:09.880374785   385 0x562f52858300 INFO                  cefsrc gstcefsrc.cc:713:run_cef: Initializing CEF
[New Thread 0x7f70a66f5640 (LWP 391)]
[Detaching after fork from child process 392]
[Detaching after fork from child process 393]
[0508/094751.768282:VERBOSE1:cdm_registration.cc(189)] Widevine enabled but no library found
[0508/094751.768284:VERBOSE1:cdm_registration.cc(189)] Widevine enabled but no library found
[0508/094751.768335:INFO:cpu_info.cc(53)] Available number of cores: 32
[0508/094751.768336:INFO:cpu_info.cc(53)] Available number of cores: 32
[0508/094751.768345:VERBOSE1:zygote_main_linux.cc(218)] ZygoteMain: initializing 0 fork delegates
[0508/094751.768346:VERBOSE1:zygote_main_linux.cc(218)] ZygoteMain: initializing 0 fork delegates
[New Thread 0x7f70a5ef4640 (LWP 394)]
[New Thread 0x7f70a56f3640 (LWP 395)]
[New Thread 0x7f70a4ef2640 (LWP 396)]
[New Thread 0x7f7093fff640 (LWP 397)]
[New Thread 0x7f70937fe640 (LWP 398)]
[New Thread 0x7f7092ffd640 (LWP 399)]
[New Thread 0x7f70927fc640 (LWP 400)]
[0508/094751.773612:VERBOSE1:pref_proxy_config_tracker_impl.cc(187)] 0x7f709c097830: set chrome proxy config service to 0x7f709c052160
[0508/094751.773870:VERBOSE1:cdm_registration.cc(189)] Widevine enabled but no library found
[New Thread 0x7f7091ffb640 (LWP 401)]
[New Thread 0x7f70917fa640 (LWP 402)]
[New Thread 0x7f7090ff9640 (LWP 403)]
[New Thread 0x7f7083fff640 (LWP 404)]
[New Thread 0x7f70837fe640 (LWP 405)]
[0508/094751.783309:VERBOSE1:pulse_util.cc(236)] Failed to connect to the context.  Error: Connection refused
[0508/094751.783339:WARNING:audio_manager_linux.cc(60)] Falling back to ALSA for audio output. PulseAudio is not available or could not be initialized.
[0508/094751.783536:VERBOSE1:webrtc_internals.cc(120)] Could not get the download directory.
[New Thread 0x7f7082ffd640 (LWP 425)]
[0508/094751.785178:VERBOSE1:media_stream_manager.cc(1065)] MSM::InitializeMaybeAsync([this=0x7f709c0047f0])
[0508/094751.785195:VERBOSE1:media_stream_manager.cc(1065)] MDM::MediaDevicesManager()
[0508/094751.785200:VERBOSE1:media_stream_manager.cc(1065)] MSM::MediaStreamManager([this=0x7f709c0047f0]))
libva error: vaGetDriverNameByIndex() failed with unknown libva error, driver_name = (null)
[0508/094751.786047:VERBOSE1:vaapi_wrapper.cc(844)] InitializeVaDriver_Locked(): vaInitialize failed: unknown libva error
[0508/094751.786776:WARNING:sandbox_linux.cc(380)] InitializeSandbox() called with multiple threads in process gpu-process.
[0508/094751.787225:VERBOSE1:component_installer.cc(285)] StartRegistration for Widevine Content Decryption Module
[0508/094751.787225:VERBOSE1:first_party_sets_handler_impl.cc(432)] Empty path. Failed loading serialized First-Party Sets file.
[0508/094751.787493:VERBOSE1:component_installer.cc(441)] FinishRegistration for Widevine Content Decryption Module
[0508/094751.787510:VERBOSE1:component_updater_service.cc(131)] CrxUpdateService starting up. First update attempt will take place in 60 seconds. Next update attempt will take place in 18000 seconds. 
[Detaching after fork from child process 431]
[0508/094751.789194:VERBOSE1:key_storage_util_linux.cc(54)] Password storage detected desktop environment: (unknown)
[0508/094751.789205:VERBOSE1:key_storage_linux.cc(123)] Selected backend for OSCrypt: BASIC_TEXT
[0508/094751.789212:VERBOSE1:key_storage_linux.cc(143)] OSCrypt did not initialize a backend.
[0508/094751.789280:VERBOSE1:pref_proxy_config_tracker_impl.cc(187)] 0x7f709c16e9c0: set chrome proxy config service to 0x7f709c1697b0

Thread 4 "CrBrowserMain" received signal SIGSEGV, Segmentation fault.
[Switching to Thread 0x7f70a7fff640 (LWP 390)]
0x00007f70b30415ae in apps::AppLifetimeMonitorFactory::GetBrowserContextToUse(content::BrowserContext*) const () at ../../extensions/browser/browser_context_keyed_api_factory.h:148
148 ../../extensions/browser/browser_context_keyed_api_factory.h: No such file or directory.
(gdb) 
(gdb) [0508/094806.801542:INFO:child_thread_impl.cc(903)] ChildThreadImpl::EnsureConnected()
bt
#0  0x00007f70b30415ae in apps::AppLifetimeMonitorFactory::GetBrowserContextToUse(content::BrowserContext*) const () at ../../extensions/browser/browser_context_keyed_api_factory.h:148
#1  0x00007f70b629854d in GetServiceForContext() () at ../../components/keyed_service/core/keyed_service_factory.cc:69
#2  0x00007f70b6c4e40a in ProfileNetworkContextService() () at ../../chrome/browser/net/profile_network_context_service.cc:307
#3  0x00007f70b6c5276a in ProfileNetworkContextServiceFactory::BuildServiceInstanceFor(content::BrowserContext*) const () at ../../chrome/browser/net/profile_network_context_service_factory.cc:47
#4  0x00007f70b62985df in GetServiceForContext() () at ../../components/keyed_service/core/keyed_service_factory.cc:93
#5  0x00007f70b0fc9586 in ConfigureNetworkContextParams() () at ../../cef/libcef/browser/alloy/alloy_content_browser_client.cc:1232
#6  0x00007f70b2c8eab9 in InitNetworkContext() () at ../../content/browser/storage_partition_impl.cc:2862
#7  0x00007f70b2c8e9f9 in GetNetworkContext() () at ../../content/browser/storage_partition_impl.cc:1414
#8  0x00007f70b2caeb4c in HandleNetworkFactoryRequestOnUIThread() () at ../../content/browser/url_loader_factory_getter.cc:304
#9  0x00007f70b2cae9fe in Initialize() () at ../../content/browser/url_loader_factory_getter.cc:143
#10 0x00007f70b2c8de23 in Initialize() () at ../../content/browser/storage_partition_impl.cc:1283
#11 0x00007f70b2c9ab7d in Get() () at ../../content/browser/storage_partition_impl_map.cc:351
#12 0x00007f70b2775e75 in GetStoragePartition () at ../../content/browser/browser_context.cc:138
#13 GetStoragePartition() () at ../../content/browser/browser_context.cc:127
#14 0x00007f70b2bb073d in MaybeTakeSpareRenderProcessHost () at ../../content/browser/renderer_host/render_process_host_impl.cc:526
#15 GetProcessHostForSiteInstance() () at ../../content/browser/renderer_host/render_process_host_impl.cc:4507
#16 0x00007f70b2c77c70 in GetProcess() () at ../../content/browser/site_instance_impl.cc:354
#17 0x00007f70b2b90093 in CreateRenderFrameHost() () at ../../content/browser/renderer_host/render_frame_host_manager.cc:2729
#18 0x00007f70b2b8ffb9 in InitRoot() () at ../../content/browser/renderer_host/render_frame_host_manager.cc:394
#19 0x00007f70b2aa9c5f in Init() () at ../../content/browser/renderer_host/frame_tree.cc:777
#20 0x00007f70b2cc64ee in Init() () at ../../content/browser/web_contents/web_contents_impl.cc:3088
#21 0x00007f70b2cb9311 in CreateWithOpener() () at ../../content/browser/web_contents/web_contents_impl.cc:1151
#22 0x00007f70b0fcf362 in CreateWebContents() () at ../../cef/libcef/browser/alloy/browser_platform_delegate_alloy.cc:106
#23 0x00007f70b0fc0622 in Create() () at ../../cef/libcef/browser/alloy/alloy_browser_host_impl.cc:112
--Type <RET> for more, q to quit, c to continue without paging--
#24 0x00007f70b0fe095a in Create () at ../../cef/libcef/browser/browser_host_create.cc:172
#25 CreateBrowserSync() () at ../../cef/libcef/browser/browser_host_create.cc:149
#26 0x00007f70b0f76d20 in cef_browser_host_create_browser_sync() () at ../../cef/libcef_dll/cpptoc/browser_host_cpptoc.cc:122
#27 0x00007f70bb242e3c in CefBrowserHost::CreateBrowserSync(CefWindowInfo const&, scoped_refptr<CefClient>, CefStringBase<CefStringTraitsUTF16> const&, CefStructBase<CefBrowserSettingsTraits> const&, scoped_refptr<CefDictionaryValue>, scoped_refptr<CefRequestContext>) () at /usr/cef/libgstcef.so
#28 0x00007f70bb23bf89 in BrowserClient::MakeBrowser(int) () at /usr/cef/libgstcef.so
#29 0x00007f70bb24ae2f in (anonymous namespace)::CefOnceClosureTask::Execute() () at /usr/cef/libgstcef.so
#30 0x00007f70bb26bd9b in (anonymous namespace)::task_execute(_cef_task_t*) () at /usr/cef/libgstcef.so
#31 0x00007f70b49d1231 in Run () at ../../base/callback.h:145
#32 RunTaskImpl() () at ../../base/task/common/task_annotator.cc:135
#33 0x00007f70b49e63b9 in RunTask<(lambda at ../../base/task/sequence_manager/thread_controller_with_message_pump_impl.cc:426:29)> () at ../../base/task/common/task_annotator.h:74
#34 DoWorkImpl() () at ../../base/task/sequence_manager/thread_controller_with_message_pump_impl.cc:424
#35 0x00007f70b49e5eea in DoWork() () at ../../base/task/sequence_manager/thread_controller_with_message_pump_impl.cc:294
#36 0x00007f70b49e6a45 in non-virtual thunk to base::sequence_manager::internal::ThreadControllerWithMessagePumpImpl::DoWork() () at /usr/cef/libcef.so
#37 0x00007f70b4993f73 in Run() () at ../../base/message_loop/message_pump_glib.cc:404
#38 0x00007f70b49e6d45 in Run() () at ../../base/task/sequence_manager/thread_controller_with_message_pump_impl.cc:577
#39 0x00007f70b49b473a in Run() () at ../../base/run_loop.cc:141
#40 0x00007f70b101f08b in RunMessageLoop() () at ../../cef/libcef/browser/main_runner.cc:281
#41 0x00007f70bb23cdb7 in run_cef(_GstCefSrc*) () at /usr/cef/libgstcef.so
#42 0x00007f70bc759a51 in  () at /lib/x86_64-linux-gnu/libglib-2.0.so.0
#43 0x00007f70bc4e1b43 in start_thread (arg=<optimized out>) at ./nptl/pthread_create.c:442
#44 0x00007f70bc572bb4 in clone () at ../sysdeps/unix/sysv/linux/x86_64/clone.S:100

Seems like it is here https://sourcegraph.com/github.com/chromium/chromium@106.0.5249.225/-/blob/extensions/browser/browser_context_keyed_api_factory.h?L148

MathieuDuponchelle commented 1 year ago

Hm, so inside CEF, I don't have input here I'm afraid. Are you still running the exact same version of cefsrc as before? I would recommend isolating what change (docker-gstreamer version / cefsrc version) triggered the issue, and perhaps also try using a more recent version of CEF, you might be running into something that has been fixed since?

SteveMcFarlin commented 1 year ago

Try using the Spotify CEF build to see if that makes a difference. I am assuming you are using restream.io's version or build scripts. I recently tested Chromium 106 with a Puppeteer based system and had lots of issues. I have been running a custom CEF build using 111 with no issues using Xvfb or a full x-server.

amyspark commented 3 months ago

Does this issue still occur post #83 ?