Skip to content

Fall back to TMPDIR for global named mutexes when /tmp is not writable - #137364

Closed
virzak wants to merge 1 commit into
dotnet:mainfrom
virzak:fix/shared-memory-no-tmp
Closed

virzak wants to merge 1 commit into
dotnet:mainfrom
virzak:fix/shared-memory-no-tmp

Conversation

@virzak

@virzak virzak commented Nov 11, 2026

Copy link
Copy Markdown
Contributor

On Android, /tmp is missing or owned by the shell user, so new Mutex(name, new NamedWaitHandleOptions { CurrentUserOnly = false }) fails with "Access to the path '/tmp/' is denied". Before the port to managed code (#117635), the PAL used /data/local/tmp/ on Android.

This falls back to the temp directory (TMPDIR) when /tmp/ isn't writable. MutexTests computes the global directory the same way instead of hardcoding /tmp/.

Tested with a Termux (linux-bionic arm64) 11.0 build: global named mutexes now work. On linux-x64, System.Threading.Tests pass both normally and with /tmp mounted read-only.

Part of #137361

On Android, /tmp is missing or owned by the shell user, so creating a
global-scope named mutex fails with "Access to the path /tmp/ is
denied". The CoreCLR PAL used /data/local/tmp/ there before the port
to managed code.
@dotnet-policy-service dotnet-policy-service Bot added the community-contribution Indicates that the PR has been added by a community member label Nov 11, 2026
@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 3 pipeline(s).
12 pipeline(s) were filtered out due to trigger conditions.
There may be pipelines that require an authorized user to comment /azp run to run.

@dotnet-policy-service

Copy link
Copy Markdown
Contributor

Tagging subscribers to this area: @dotnet/area-system-io
See info in area-owners.md if you want to be subscribed.

@jkoritzinsky

Copy link
Copy Markdown
Member

I think it would be better for linux-bionic to go onto the "mobile" plan for named mutexes (in-proc only).

@virzak

virzak commented Nov 11, 2026

Copy link
Copy Markdown
Contributor Author

linux-bionic is mostly used by Termux, which runs many .NET processes side by side. Roslyn's compiler server, the MSBuild server and the Razor server find each other through named mutexes, and the user-scoped ones already work there today (they go under $HOME). In-proc only would make every dotnet build start a new compiler server. This PR only fixes the global scope, which currently throws because /tmp isn't writable for apps.

@dotnet-policy-service

Copy link
Copy Markdown
Contributor

Tagging subscribers to this area: @JulieLeeMSFT, @VSadov
See info in area-owners.md if you want to be subscribed.

@jkotas

jkotas commented Nov 11, 2026

Copy link
Copy Markdown
Member

Roslyn's compiler server, the MSBuild server and the Razor server find each other through named mutexes,

All these should be using user-local mutexes now.

Is TMPDIR a global (shared by all users) location or user-local location under TermUX?

@jkotas

jkotas commented Nov 11, 2026

Copy link
Copy Markdown
Member

This PR only fixes the global scope, which currently throws because /tmp isn't writable for apps.

Is there a global (shared by all users/apps) location to use for the global scope? If not, I think the current behavior is correct.

@virzak

virzak commented Nov 12, 2026

Copy link
Copy Markdown
Contributor Author

TMPDIR is private to the Termux app; all Termux processes run as the app's uid. Android has no location shared across apps, so there isn't a real global one. Agreed the current behavior is correct; closing.

@virzak virzak closed this Nov 12, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area-System.Threading community-contribution Indicates that the PR has been added by a community member

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants