protonscr

Steam downloader uses flock(LOCK_EX) on files opened O_RDONLY

steamclosed
ValveSoftware/steam-for-linux#6392 · opened 2019-07-14 by eqvinox · updated 2019-07-14 · 3 comments · github
Eeqvinox 2019-07-14 github

Your system information

  • Steam client version (build number or date): Jun 17 2019, 23:31:27
  • Distribution (e.g. Ubuntu): Debian 10
  • Opted into Steam client beta?: no
  • Have you checked for system updates?: yes

Please describe your issue in as much detail as possible:

The Steam downloader (for client updates, game downloads as well as workshop downloads) seems to be locking files using ~flock(LOCK_EX)~ flock(LOCK_SH). However, the files seem to be opened using ~open(O_RDONLY)~ open(O_WRONLY), which does not work on NFS(v4) file systems. Files must be opened as open(O_RDWR) to take a ~LOCK_EX~ LOCK_SH lock.

Steps for reproducing this issue:

  1. mount directory used by steam itself (or some game) over NFS(v4)
  2. try downloading anything
  3. the download fails ("Disk write error")

The problem occurs with these directories:

  • ...steam/steamapps/downloading
  • ...steam/steamapps/workshop/downloads
  • ~/.local/share/Steam

Steps for fixing this issue:

  1. grep through your code base for uses of ~LOCK_EX~ LOCK_SH
  2. make sure the fds used in these flock() calls are opened for read-write access (O_RDWR), not ~read~ write-only access (~O_RDONLY~ O_WRONLY).
Kkisak-valve maintainer 2019-07-14 github

Possible duplicate of #5788.

Eeqvinox 2019-07-14 github

@kisak-valve yes, it's duplicate.

Also, I got the flags the wrong way around. It's failing because it's LOCK_SH and the files are opened write-only O_WRONLY.

On NFSv4:

  • LOCK_SH only works if the file is opened for reading
  • LOCK_EX only works if the file is opened for writing

In both cases, the "other" direction is irrelevant, i.e. O_RDWR works in all cases.

Kkisak-valve maintainer 2019-07-14 github

Thanks for confirming it's a duplicate. ~I've transferred this issue to https://github.com/ValveSoftware/steam-for-linux/issues/5788#issuecomment-511219079 so we can keep the discussion together.~ Removed in favor of https://github.com/ValveSoftware/steam-for-linux/issues/5788#issuecomment-511219089.

Closing in favor of the existing issue report.