Repository navigation
fix: unlock the OS thread when ScopeUserByIds fails - #899
Merged
butonic merged 1 commit intoOct 26, 2026
Merged
Conversation
aduffeck
reviewed
Oct 23, 2026
aduffeck
left a comment
Member
There was a problem hiding this comment.
nice find, lgtm 👍 (except the utils/decomposedfs changes)
UnixMapper.ScopeUserByIds locks the goroutine to its OS thread before it switches the fsuid and the fsgid, as they belong to the thread. The function it returns restores them and unlocks the thread again. On an error, though, it returned without that function and without unlocking: the goroutine stayed locked to its thread for good, and a fsuid it had already switched before the fsgid failed was not restored. For a short-lived goroutine of a request, Go discards the locked thread when the goroutine ends. Long-lived goroutines would stay pinned to their thread after a single failure, with one more lock nested for every further one. The background workers of the revision cleanup proposed in opencloud-eu#895 are such goroutines: with use_space_groups, they switch to the group of a space for every file. ScopeUserByIds now restores the fsuid and unlocks the thread on every error path. Tests: the fsuid and fsgid are restored after switching, and unchanged after a failed switch to a group the process is not in (skipped where the switch succeeds, e.g. as root). Whether the thread was unlocked can't be observed from Go, there is no API to query it.
pbleser-oc
force-pushed
the
fix/scope-user-by-ids-unlock-thread
branch
from
October 23, 2026 06:49
25f4981 to
e6ece73
Compare
butonic
approved these changes
Oct 23, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
UnixMapper.ScopeUserByIdslocks the goroutine to its OS thread (runtime.LockOSThread) before it switches the fsuid and the fsgid, as they belong to the thread, not to the goroutine. The function it returns restores them and unlocks the thread again.On an error, though, it returned without that function and without unlocking:
For the short-lived goroutine of a request, that is mostly harmless: Go discards a locked thread when its goroutine ends. Long-lived goroutines, though, would stay pinned to their thread after a single failure, with one more lock nested for every further one. The background workers of the revision cleanup proposed in #895 are such goroutines: with
use_space_groups, they switch to the group of a space for every file. Split off from #895, as suggested in its review.Changes
ScopeUserByIdsnow restores the fsuid and unlocks the thread on every error path. The comments explain why the unlock is needed.Tests
The fsuid and fsgid are restored after switching, and unchanged after a failed switch to a group the process is not in. The latter is skipped where the switch succeeds, e.g. when running as root or with
CAP_SETGID. Whether the thread was unlocked can't be tested: Go has no API to query whether a goroutine is locked to its thread.