Repository navigation
Description
Description
When I'm trying to test Jellyfin with recent dotnet 7 upgrade, I noticed that the library scan would cause segfault on all arm64 platforms I've been tested on(Linux and macOS). When doing a library scan with lots of video files, which I have 80 in my test folder and it reliably caused the segfault).
I've tested x86-64 on Windows and it runs fine, which led me to believe this is an arm64 specific issue.
I also noticed that if you try to attach a dotnet debugger to the process, the segfault would gone.
What I've tried to workaround this so far:
- Use
COMPlus_GCName=libclrgc.so, still segfaults - Use server gc, still segfaults
I also tried to get a coredump for the process, but it is too big to upload here. If that is needed please let me know.
Reproduction Steps
I'm sorry I cannot come up with a simpler reproduction step because it is hard for me to extract a code pattern that would cause the segfault. So I will tell you how to reproduce it with jellyfin:
- Initial account creation may not be triggered for the master branch, so I would suggest you to install a release version of Jellyfin 10.8.11, start that first, then complete the account creation step in the web UI but don't add any library folders yet.
git clone https://github.com/jellyfin/jellyfin.git
cd jellyfin
dotnet publish --config Release
cd /Jellyfin.Server/bin/Release/net7.0
# if you are on Linux, you should mv jellyfin jellyfin-server
wget https://repo.jellyfin.org/releases/server/portable/versions/unstable/web/20231005.2/jellyfin-web_20231005.2_portable.tar.gz
tar xvf jellyfin-web_20231005.2_portable.tar.gz
mv jellyfin-web_20231005.2 jellyfin-web
# change the data-dir to the path pointed by the one created by the release version of Jellyfin 10.8.11
./jellyfin-server --datadir ~/jellyfin-dataAfter that, go to localhost:8096, log in with the account created by the release version, and add a media library that points to the folder containing a lot of video files. Mine are all h264 encoded in mp4 or flv containers. (You can find the option at the menu button at the top left corner. Click on Dashboard, then click on Libraries.)
You will see a segfault near the end of the Library scan.
Expected behavior
The Library scan should success.
Actual behavior
dotnet runtime segfaults.
Regression?
No response
Known Workarounds
No response
Configuration
mcr.microsoft.com/dotnet/sdk:7.0-bookworm-slim docker image on Linux arm64
dotnet 7.0.401 on macOS 14.0 arm64
Other information
No response
Activity
EgorBo commentedon Oct 5, 2023
Can you please check with
DOTNET_EnableWriteXorExecute=0env variable and separately withDOTNET_JITMinOpts=1gnattu commentedon Oct 5, 2023
I tried
DOTNET_EnableWriteXorExecute=0, and it still segfaults. However, withDOTNET_JITMinOpts=1, the segfaults seem to be gone for me. I've tested multiple folders multiple times and have not triggered a segfault so far. I'm going to use this as the workaround for the moment.EgorBo commentedon Oct 5, 2023
Thanks! Smells like a codegen issue then - can you possibly try with a public version .NET 8.0 RC1 (or better RC2 once it's released)?
jakobbotsch commentedon Oct 5, 2023
Does it reproduce with
DOTNET_JitEnablePhysicalPromotion=0?gnattu commentedon Oct 5, 2023
@jakobbotsch Yes, it still segfaults with
DOTNET_JitEnablePhysicalPromotion=0jakobbotsch commentedon Oct 5, 2023
Did this work in a previous .NET 7 release? Or did you upgrade from a previous major version?
gnattu commentedon Oct 5, 2023
I've tested this with dotnet version as early as
7.0.102and still encountering the issue. I have not tested in previous dotnet 7 releases.The current master is using some methods introduced in dotnet7, but if I revert these commits and do a quick dirty test on dotnet
6.0.400, the segfault is gone.gnattu commentedon Oct 5, 2023
@EgorBo Sorry, I pulled the 8.0 RC1 Docker image, but our codebase is not working well with .NET 8.0 and cannot be tested with a simple upgrade. We're encountering a lot of compiler errors like the CS0104 and need manual modifications. I attempted to fix these, but it seems like something went wrong or it's indeed broken in 8.0. The server cannot find the network config and cannot be started after my modifications. I'm sorry, but I probably can't test any further on 8.0, as it requires some work for a proper migration, and we're not planning on upgrading to 8.0 yet.
5 remaining items
gnattu commentedon Oct 10, 2023
@kunalspathak
I don't have bare metal Windows arm64 machine, but I started an Windows 11 arm64 VM and tested on that. The same folder indeed did not segfaults on windows arm64.
Tested on : Windows 11 Pro 22H2, build 22621.2134 arm64, dotnet 7.0.402
On macOS, the exact version dotnet 7.0.402, it segfaults.
It crashes. To have a better understanding of what happened you can go to jellyfin-data dir, look for config folder, and you will find (or to create) a logging.json and set logging level to debug:
{ "Serilog": { "MinimumLevel": "Debug" } }Then you will find that the segfault would occur when the scan progress is near to an end:
Pay attention to
OnRefreshProgressbecause most of the time the segfault occurs whenOnRefreshProgressis close to 100, in rare case, it could finish to 100 and getOnRefreshCompleteprinted, but it would still segfault after that.Sorry but all our unit test files are passed, which makes this problem tricky. I used a docker container and redirected its port, so that I can use my browser to connect it remotely, despite the container/linux host been cli based. My method of testing is that:
dotnet publishwith Release config, and then copy the jellyfin-web folder to the published folder.mv jellyfin jellyfin-serverbecause jellyfin will want to create a config folder at its working dir../jellyfin-server --datadir ~/jellyfin-dataIf you want to test it without a container, the procedure is similar, just running it directly instead. Jellyfin defaults to listen on 0.0.0.0 so you don't need to do extra configuration to get remote connection.
Some things to note during testing:
Refresh metadata, you need to chooseReplace all metadata, other options do not trigger segfault.apt install ffmpeg.kunalspathak commentedon Oct 25, 2023
@gnattu - is it possible to get the native callstack when it seg faults? I just investigated #93912 of a crash in net7/arm64 and was caused because of
Vector128.Load. I looked through thejellyfincodebase and don't see any references ofVector128, but some other dependency might be using it. Curious to see if it is the same reason.gnattu commentedon Oct 25, 2023
@kunalspathak I tried to get a backtrace using lldb but the backtrace does not show many useful data:
Is there anything I have to do to show more detailed data?
gnattu commentedon Oct 25, 2023
I just used captured another and this time it comes with more useful info:
gnattu commentedon Oct 25, 2023
I'm a little bit confused because the thread stopped at different places in different runs:
Run1:
Run2:
Run3:
kunalspathak commentedon Oct 25, 2023
Can you try
gdbon linux/arm64? We need call stack of user thread, the ones you shared our from threadpool worker thread and are just waiting to receive the work.gnattu commentedon Oct 25, 2023
Alright, I repeated using gdb on linux/arm64 with all the debug symbols downloaded:
Now it looks like it is from a very similar cause in #93912.
kunalspathak commentedon Oct 25, 2023
Yep, it is.
kunalspathak commentedon Oct 25, 2023
@gnattu - I have submitted #93983, but wondering if upgrading to .NET8 an option for you?
gnattu commentedon Oct 26, 2023
No, upgrading to .NET 8 requires more effort than we can currently undertake. I downloaded the artifacts from Azure Pipeline in #93992 and overwrote the
libcoreclrandlibclrjit. I confirmed that Jellyfin no longer crashes.