fix(steam): the parallel installer claims packages under a flock (#3145)

The parallel workers claimed packages with mkdir, which is not atomic in the app's guest shell: two workers sometimes took the same package and about 3 installs in 8 failed on a device. Claims now come from a counter under a flock, and a counter that cannot be read or written fails the worker.
This commit is contained in:
Kurt Himebauch authored and GitHub committed 2026-11-24 09:51:16 -05:00
1 parent cf44aaed14
commit c1dd542f97
2 files changed
+63 -6

No files matched your search

+40
View File
@@ -613,6 +613,46 @@ with open(log, 'a') as out:
self.assertIn('downloading Steam: a_all (1/2), 0 of 2 MB\n', result.stdout)
self.assertIn('downloading Steam: client_linuxarm64_linuxarm64 (2/2), 1 of 2 MB\n', result.stdout)
def test_workers_do_not_claim_packages_with_mkdir(self):
source = SCRIPT.read_text()
region = source[source.index('run_parallel() {'):source.index('fetch_manifest() {')]
self.assertNotIn('mkdir "$state/claim', region)
self.assertIn('claim_next', region)
@unittest.skipUnless(shutil.which('flock'), 'needs flock')
def test_racing_workers_never_get_the_same_package(self):
source = SCRIPT.read_text()
start = source.index('claim_next() {')
function = source[start:source.index('\n}\n', start) + 3]
state = self.root / 'claims'
state.mkdir()
(state / 'next').write_text('1\n')
script = 'state=$1\ncount=$2\n' + function + 'while :; do n=$(claim_next); [ "$n" -gt 0 ] || exit 0; echo "$n"; done\n'
workers = [subprocess.Popen(['bash', '-c', script, 'bash', str(state), '300'], stdout=subprocess.PIPE, text=True)
for _ in range(8)]
claimed = []
for worker in workers:
out, _ = worker.communicate(timeout=120)
self.assertEqual(0, worker.returncode)
claimed += [int(n) for n in out.split()]
self.assertEqual(sorted(claimed), list(range(1, 301)), 'a package was claimed twice or never')
@unittest.skipUnless(shutil.which('flock'), 'needs flock')
def test_a_counter_that_cannot_be_used_fails_the_claim(self):
source = SCRIPT.read_text()
start = source.index('claim_next() {')
function = source[start:source.index('\n}\n', start) + 3]
for broken in ('directory', 'empty', 'text'):
state = self.root / f'claims-{broken}'
state.mkdir()
if broken == 'directory':
(state / 'next').mkdir()
else:
(state / 'next').write_text('' if broken == 'empty' else 'abc\n')
script = 'state=$1\ncount=5\n' + function + 'n=$(claim_next) && echo "claimed $n" || echo failed\n'
result = subprocess.run(['bash', '-c', script, 'bash', str(state)], text=True, capture_output=True, timeout=30)
self.assertEqual('failed', result.stdout.strip(), f'{broken}: {result.stdout!r} {result.stderr!r}')
def test_the_parallel_workers_use_no_process_substitution(self):
source = SCRIPT.read_text()
region = source[source.index('fetch_one() {'):source.index('fetch_manifest() {')]