Skip to content

Make set_umask/get_umask thread safe#69842

Open
geoffberger wants to merge 1 commit into
saltstack:3006.xfrom
geoffberger:fix-umask-thread-safety
Open

Make set_umask/get_umask thread safe#69842
geoffberger wants to merge 1 commit into
saltstack:3006.xfrom
geoffberger:fix-umask-thread-safety

Conversation

@geoffberger

Copy link
Copy Markdown

What does this PR do?

Serializes set_umask/get_umask with an RLock. umask is process wide, so two threads overlapping in set_umask restore each other's saved value and the process umask stays changed for good.

We hit this in salt-api: mk_key wraps key writes in set_umask(0o277) on every netapi request and rest_cherrypy runs requests in a thread pool. Once the umask stuck at 0o277, every jid file and thin bundle came out unwritable and every client=ssh request 500'd until a restart. Confirmed via /proc/<pid>/status showing Umask: 0277 on the salt-api process while the master sat at 0022.

What issues does this PR fix or reference?

Fixes #66607

Previous Behavior

Concurrent set_umask/get_umask calls race and can leave the process umask permanently changed.

New Behavior

umask set/restore is serialized. Nested set_umask in a single thread still works (RLock).

Merge requirements satisfied?

Commits signed with GPG?

No

@geoffberger
geoffberger requested a review from a team as a code owner July 21, 2026 23:59
@welcome

welcome Bot commented Jul 21, 2026

Copy link
Copy Markdown

Hi there! Welcome to the Salt Community! Thank you for making your first contribution. We have a lengthy process for issues and PRs. Someone from the Core Team will follow up as soon as possible. In the meantime, here's some information that may help as you continue your Salt journey.
Please be sure to review our Code of Conduct. Also, check out some of our community resources including:

There are lots of ways to get involved in our community. Every month, there are around a dozen opportunities to meet with other contributors and the Salt Core team and collaborate in real time. The best way to keep track is by subscribing to the Salt Community Events Calendar.
If you have additional questions, email us at saltproject.pdl@broadcom.com. We're glad you've joined our community and look forward to doing awesome things with you!

@twangboy twangboy added the test:full Run the full test suite label Jul 23, 2026
@twangboy twangboy added this to the Sulphur v3006.28 milestone Jul 23, 2026
umask is process wide. Two threads overlapping in set_umask restore
each other's saved value and the process umask stays changed for good.
Hit this in salt-api: mk_key wraps key writes in set_umask(0o277) on
every netapi request, rest_cherrypy runs requests in a thread pool,
and once the umask stuck at 0o277 every jid file and thin bundle came
out unwritable. Serialize both helpers with an RLock so nested use in
a single thread still works.

Fixes saltstack#66607
@twangboy
twangboy force-pushed the fix-umask-thread-safety branch from 020589f to 1ad9ce2 Compare July 23, 2026 16:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

test:full Run the full test suite

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants