Skip to content

Fix race condition in MemoryUserDatabase.save() by extending lock scope#1014

Open
sahvx655-wq wants to merge 1 commit into
apache:mainfrom
sahvx655-wq:fix/memory-user-db-race-condition
Open

Fix race condition in MemoryUserDatabase.save() by extending lock scope#1014
sahvx655-wq wants to merge 1 commit into
apache:mainfrom
sahvx655-wq:fix/memory-user-db-race-condition

Conversation

@sahvx655-wq
Copy link
Copy Markdown
Contributor

This PR fixes a concurrency issue in MemoryUserDatabase.save() where file rename operations were performed after releasing the writeLock.

Under concurrent save requests, multiple threads could interfere with the same .new and .old files, leading to IOExceptions or inconsistent tomcat-users.xml state.

This change extends the writeLock scope to cover the complete file replacement workflow, ensuring the save operation remains atomic.

Changes
Hold writeLock until all rename operations complete
Move backup/rename logic inside the protected section
Add TestMemoryUserDatabaseConcurrency.java regression test

@sahvx655-wq sahvx655-wq force-pushed the fix/memory-user-db-race-condition branch from 1182414 to 6c4b3e1 Compare May 29, 2026 06:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant