protonscr

Downloading a large game can fail with EMFILE (errno 24)

steamclosed Steam client
ValveSoftware/steam-for-linux#7956 · opened 2021-07-30 by smcv · updated 2021-08-04 · 11 comments · github
1 matching comments, n / p to jump
Ssmcv 2021-07-30 github

Your system information

  • Steam client version (build number or date): 1627607186
  • Distribution (e.g. Ubuntu): Debian 11
  • Opted into Steam client beta?: yes
  • Have you checked for system updates?: yes

Please describe your issue in as much detail as possible:

Downloading Civ VI gets paused after a while with "Disk write error". Looking at ~/.steam/root/logs/content_log.txt I see this:

[2021-07-30 18:47:14] Downloading 35959 chunks from depot 533503
[2021-07-30 18:47:26] Increasing target number of download connections to 4 (rate was 0.000, now 53.843)
[2021-07-30 18:47:26] Current download rate: 53.843 Mbps
[2021-07-30 18:47:26] Created download interface of type 'SteamCache' (7) to host cache1-lhr1.steamcontent.com (cache1-lhr1.steamcontent.com)
[2021-07-30 18:48:21] CGenericAsyncFileIOThread::AllocateResource() failed for CFileWriter: errno: 24, File: /home/steam/SteamLibrary/steamapps/downloading/289070/steamassets/base/platforms/windows/audio/751812779.wem
[2021-07-30 18:48:21] Failed to write chunk in file "steamassets\base\platforms\windows\audio\751812779.wem", 266788 bytes at offset 0 (File Not Found)
[2021-07-30 18:48:21] AppID 289070 update canceled : Failed updating depot 533503 while writing chunk, offset 0 (File Not Found) (Disk write failure) "/home/steam/SteamLibrary/steamapps/downloading/289070/steamassets/base/platforms/windows/audio/751812779.wem"
[2021-07-30 18:48:21] CGenericAsyncFileIOThread::AllocateResource() failed for CFileWriter: errno: 24, File: /home/steam/SteamLibrary/steamapps/downloading/289070/steamassets/base/platforms/windows/audio/748790226.wem

errno 24 is EMFILE, "Too many open files", which means RLIMIT_NOFILE is being reached, i.e. Steam is trying to open a very large number of file descriptors. Looking in /proc/$pid/fd/ for the main Steam process, I can see that there are about 1000 fds just before it fails.

By default, Debian sets most user processes to have a RLIMIT_NOFILE soft limit of 1024, and a hard limit of 1024*1024. This is the same as the recommendation in Proton's Wine esync branch, and similar to systemd recommendations (systemd actually defaults to a hard limit of 512*1024, but the exact number doesn't really matter).

The main reason why the soft limit is only 1024 is that programs that use select(2) will fail horribly under any RLIMIT_NOFILE higher than that. A few other programs, notably Java interpreters, also cope badly with high numbers.

There are two ways that Steam can avoid this bug:

  • Stop trying to open files before EMFILE is reached, or at the very latest, when EMFILE is reached. A few hundred files open is probably plenty - if Steam is downloading a lot of files in parallel, there are going to be diminishing returns.

-and/or-

  • Set a higher RLIMIT_NOFILE for Steam, but not its subprocesses
    • technically it can be anything <= the hard limit, but some older Linux systems set the hard limit to only 4096
    • this only works if Steam always uses poll() or epoll, and never select()
    • if going this route, it's important to drop the soft RLIMIT_NOFILE back down to 1024 when launching any subprocess whose code is not entirely under Valve's control, in particular games and diagnostic tools

Steps for reproducing this issue:

  1. Have Debian's default RLIMIT_NOFILE: soft limit 1024, hard limit 1024*1024 (other distributions that use soft limit 1024 and hard limit 512*1024 would probably also trigger this, it's the soft limit of 1024 that matters)
  2. Have a large game not installed - I used Civilization VI (289070). It might have to be a game with a large number of small files.
  3. Install the game
Mmindcombatant 2021-07-30 github

Just ran into this same issue on Ubuntu 20.04.2, latest July 30th Steam Client beta, with Omno and even the latest Proton Experimental, similar lines in content_log.txt for both apps.

PPedroHLC 2021-08-02 github
Having the same thing with ArchLinux, latest Steam Beta (30/07/2021 21:28:07), ZFS:

[2021-08-02 18:23:32] AppID 1686450 update changed : Running,
[2021-08-02 18:23:32] AppID 1686450 update started : download 1274989264/1884205488, store 0/0, reuse 0/0, delta 0/0, stage 2881567184/4242800593
[2021-08-02 18:23:32] AppID 1686450 update changed : Running,Downloading,Staging,
[2021-08-02 18:23:32] Downloading 7257 chunks from depot 1686451
[2021-08-02 18:24:16] HTTP (CDN,11) - steampipe.akamaized.net (23.63.246.145:443 / 23.63.246.145:443, host: steampipe.akamaized.net): Received 504 (G
ateway Time-out) HTTP response for depot 1686451
[2021-08-02 18:24:16] HTTP (CDN,11) - steampipe.akamaized.net (23.63.246.145:443 / 23.63.246.145:443, host: steampipe.akamaized.net): Closing connect
ion
[2021-08-02 18:24:16] Got 2 download sources and 0 caching proxies via ContentServerDirectoryService::BYieldingGetServersForSteamPipe (CellID 25 / La
uncher 0)
[2021-08-02 18:24:16] Created download interface of type 'SteamCache' (7) to host cache6-gru1.steamcontent.com (cache6-gru1.steamcontent.com)
[2021-08-02 18:24:16] Created download interface of type 'CDN' (2) to host f3b7q2p3.ssl.hwcdn.net (f3b7q2p3.ssl.hwcdn.net)
[2021-08-02 18:24:17] HTTP (CDN,4) - f3b7q2p3.ssl.hwcdn.net (0.0.0.0:0 / 0.0.0.0:0, host: f3b7q2p3.ssl.hwcdn.net): AuthenticateDepotID (1686451) - Su
ccess!
[2021-08-02 18:24:29] Current download rate: 9.121 Mbps
[2021-08-02 18:24:43] CGenericAsyncFileIOThread::AllocateResource() failed for CFileWriter: errno: 24, File: /home/pedrohlc/.local/share/Steam/steama
pps/downloading/1686450/NanosWorld/Content/NanosWorld/Thumbnails/SM_Shoes.jpg
[2021-08-02 18:24:43] CGenericAsyncFileIOThread::AllocateResource() failed for CFileWriter: errno: 24, File: /home/pedrohlc/.local/share/Steam/steama
pps/downloading/1686450/NanosWorld/Content/NanosWorld/Thumbnails/SM_Toolbox_06.jpg
[2021-08-02 18:24:43] CGenericAsyncFileIOThread::AllocateResource() failed for CFileWriter: errno: 24, File: /home/pedrohlc/.local/share/Steam/steama
pps/downloading/1686450/NanosWorld/Content/NanosWorld/Thumbnails/SM_Torch.jpg
[2021-08-02 18:24:44] Failed to write chunk in file "NanosWorld\Content\NanosWorld\Thumbnails\SM_Shoes.jpg", 9439 bytes at offset 0 (File Not Found)
[2021-08-02 18:24:44] AppID 1686450 update canceled : Failed updating depot 1686451 while writing chunk, offset 0 (File Not Found) (Disk write failur
e) "/home/pedrohlc/.local/share/Steam/steamapps/downloading/1686450/NanosWorld/Content/NanosWorld/Thumbnails/SM_Shoes.jpg"
[2021-08-02 18:24:44] AppID 1686450 update changed : Running,Downloading,Staging,Stopping,
[2021-08-02 18:24:44] AppID 1686450 update changed : Running,Stopping,
[2021-08-02 18:24:44] AppID 1686450 update changed : None
[2021-08-02 18:24:44] AppID 1686450 state changed : Update Required,Update Queued,Update Started, (Disk write failure)
[2021-08-02 18:24:44] AppID 1686450 state changed : Update Required,Update Paused,Update Started,
[2021-08-02 18:24:44] AppID 1686450 scheduler finished : removed from schedule (result Disk write failure, state 0x602)

If you keep retrying it eventually finishes... Validating the files after it shows no files to redownload.

It spawns like 100 fds per sec in /proc/$pid/fd/...

Mmindcombatant 2021-08-02 github

If you keep retrying it eventually finishes...

I found this is also true in my case, also I guess I should also mention that my filesystem is also ZFS, in case this is somehow a component.

Ssmcv 2021-08-03 github

I don't think the specific filesystem is significant here (it's certainly not ZFS-specific, the system for which I reported this is using btrfs for the Steam library). errno 24 is EMFILE, which is to do with a resource limit that's enforced generically across all filesystems.

TTTimo 2021-08-03 github

The Aug 2nd beta update brought the open files count during download back down. This problem may be less prevalent now. It's possible we are leaking fds though so we'll keep an eye on it. Bumping up the open file limit as @smcv describes will be a good thing to do either way.

RRyuzakiKK 2021-08-03 github

@TTimo the Aug 2nd beta probably helps but doesn't seem to be enough. I just tried to download a 160MB update for Wreckfest (228380) and it failed after just 1.6 MB with the content_log.txt filled with hundreds of CGenericAsyncFileIOThread::AllocateResource() failed for CFileWriter: errno: 24.

PPedroHLC 2021-08-03 github

I'm no longer able to reproduce it with built Aug 2, 2021, 23:01. But I can see it opened 1600+ file descriptors.

TTheGreatestJannet 2021-08-03 github

@TTimo the Aug 2nd beta probably helps but doesn't seem to be enough. I just tried to download a 160MB update for Wreckfest (228380) and it failed after just 1.6 MB with the content_log.txt filled with hundreds of CGenericAsyncFileIOThread::AllocateResource() failed for CFileWriter: errno: 24.

Yep I had the exact same issue with the Wreckfest update. Spamming retry make it install eventually. I am running the Aug 2 2021 Beta Client.

TTheGreatestJannet 2021-08-03 github
Ssmcv 2021-08-04 github

The August 3rd update seems to have resolved this. I uninstalled Civ VI and was able to re-download it on the first attempt.

Ssmcv 2021-08-04 github

With the August 3rd update I notice that the soft limit for game subprocesses is higher than 1024 (slightly more than 2000, varying). This is likely to make some games crash (particularly if they're using select()) or run slowly. I'd recommend resetting the soft limit to be <= 1024 when executing any subprocess.

Proton versions