Fix race condition during initial admin account creation (#26036)

* Update README.md

* Update README.md

* Update README.md

* Remove link to non-existent newsletter

Also format with `yarn lint:fix` as noted in the contributing guide.

* Update README.md

* Update good first issues query

* Fix race condition during initial admin account creation

* Update core/src/main/java/hudson/security/HudsonPrivateSecurityRealm.java

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>

* Use synchronized method for initial admin account creation

---------

Co-authored-by: Mark Waite <mark.earl.waite@gmail.com>
Co-authored-by: Kris Stern <krisstern@outlook.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
This commit is contained in:
authored and GitHub committed 2026-01-04 20:17:14 -07:00
1 parent bcbe63159d
commit c2fd9da8bc
1 file changed
+4 -1
@@ -363,11 +363,14 @@ public class HudsonPrivateSecurityRealm extends AbstractPasswordBasedSecurityRea
* This can be run by anyone, but only to create the very first user account.
*/
@RequirePOST
public void doCreateFirstAccount(StaplerRequest2 req, StaplerResponse2 rsp) throws IOException, ServletException {
public synchronized void doCreateFirstAccount(StaplerRequest2 req, StaplerResponse2 rsp)
throws IOException, ServletException {
if (hasSomeUser()) {
rsp.sendError(SC_UNAUTHORIZED, "First user was already created");
return;
}
User u = createAccount(req, rsp, false, "firstUser.jelly");
if (u != null) {
tryToMakeAdmin(u);