Skip to content

[JENKINS-43936] Performance issues caused by User.getOrCreate #22055

Closed

Description

@jenkins-infra-bot

According to the source code, when executing User.getOrCreate() this code is executed all the time even if the user is in memory. It only needs to be done once - which should be if the user is not in memory (ie do it once when the user is loaded) - after which it is in the map of loaded users - no need to do it again - ever.... (until Jenkins restart).

One simple solution seems to be to change

if (!configFile.isFile() && !configFile.getParentFile().isDirectory()) {

per

if (u == null && !configFile.isFile() && !configFile.getParentFile().isDirectory()) {

The typical stacktrace I am seeing on Jenkins instance which reveal this is an issue is:

"Handling GET /m2/securityRealm/finishLogin from X.X.X.X : RequestHandlerThread[#4449]" #326951 daemon prio=5 os_prio=0 tid=0x00007fb1f1480000 nid=0x2b0d runnable [0x00007fb1a3b2f000]
   java.lang.Thread.State: RUNNABLE
	at java.io.UnixFileSystem.getBooleanAttributes0(Native Method)
	at java.io.UnixFileSystem.getBooleanAttributes(UnixFileSystem.java:242)
	at java.io.File.isFile(File.java:882)
	at hudson.model.User.getOrCreate(User.java:429)
	at hudson.model.User.getById(User.java:529)
	at hudson.model.User$UserIDCanonicalIdResolver.resolveCanonicalId(User.java:1071)
	at hudson.model.User.get(User.java:399)
	at hudson.model.User.get(User.java:368)
	at hudson.model.User.get(User.java:488)

For the moment, it seems to be only a problem on NFS systems with perhaps a non very good performance.


Originally reported by fbelzunc, imported from: Performance issues caused by User.getOrCreate
  • assignee: fbelzunc
  • status: Resolved
  • priority: Major
  • component(s): core
  • label(s): 2.46.3-fixed
  • resolution: Fixed
  • resolved: 2017-04-29T15:44:59+00:00
  • votes: 0
  • watchers: 3
  • imported: 2025-11-24
Raw content of original issue

According to the source code, when executing User.getOrCreate() this code is executed all the time even if the user is in memory. It only needs to be done once - which should be if the user is not in memory (ie do it once when the user is loaded) - after which it is in the map of loaded users - no need to do it again - ever.... (until Jenkins restart).

One simple solution seems to be to change

if (!configFile.isFile() && !configFile.getParentFile().isDirectory()) {

per

if (u == null && !configFile.isFile() && !configFile.getParentFile().isDirectory()) {

The typical stacktrace I am seeing on Jenkins instance which reveal this is an issue is:

"Handling GET /m2/securityRealm/finishLogin from X.X.X.X : RequestHandlerThread[#4449]" #326951 daemon prio=5 os_prio=0 tid=0x00007fb1f1480000 nid=0x2b0d runnable [0x00007fb1a3b2f000]
   java.lang.Thread.State: RUNNABLE
	at java.io.UnixFileSystem.getBooleanAttributes0(Native Method)
	at java.io.UnixFileSystem.getBooleanAttributes(UnixFileSystem.java:242)
	at java.io.File.isFile(File.java:882)
	at hudson.model.User.getOrCreate(User.java:429)
	at hudson.model.User.getById(User.java:529)
	at hudson.model.User$UserIDCanonicalIdResolver.resolveCanonicalId(User.java:1071)
	at hudson.model.User.get(User.java:399)
	at hudson.model.User.get(User.java:368)
	at hudson.model.User.get(User.java:488)

For the moment, it seems to be only a problem on NFS systems with perhaps a non very good performance.

Activity

  1. jenkins-infra-bot commented on Apr 29, 2017

    @jenkins-infra-bot
    Author
    scm_issue_link:

    Code changed in jenkins
    User: Félix Belzunce Arcos
    Path:
    core/src/main/java/hudson/model/User.java
    http://jenkins-ci.org/commit/jenkins/f091c9de34e2c8fcaf93966180226dea52f90e38
    Log:
    JENKINS-43936 Only migrate legacy users once per restart

  2. jenkins-infra-bot commented on Apr 29, 2017

    @jenkins-infra-bot
    Author
    scm_issue_link:

    Code changed in jenkins
    User: Oleg Nenashev
    Path:
    core/src/main/java/hudson/model/User.java
    http://jenkins-ci.org/commit/jenkins/8a48e0ccb9273d91eb74bf3c07f71d1d7aab16dc
    Log:
    Merge pull request #2862 from fbelzunc/JENKINS-43936

    [FIXED JENKINS-43936] Only migrate legacy users once per restart

    Compare: 6ff5086...8a48e0c

  3. jenkins-infra-bot commented on May 2, 2017

    @jenkins-infra-bot
    Author
    oleg_nenashev:
    • Original comment link
    • Raw content of original comment:

      The fix has been released in 2.58. I have marked it as a LTS candidate

    The fix has been released in 2.58. I have marked it as a LTS candidate

  4. jenkins-infra-bot commented on Oct 11, 2017

    @jenkins-infra-bot
    Author
    scm_issue_link:

    Code changed in jenkins
    User: Félix Belzunce Arcos
    Path:
    core/src/main/java/hudson/model/User.java
    http://jenkins-ci.org/commit/jenkins/1c56f01283719e8ade32e872ef9fa636a4437d2e
    Log:
    JENKINS-43936 Only migrate legacy users once per restart

    (cherry picked from commit f091c9d)

  5. jenkins-infra-bot commented on Nov 20, 2017

    @jenkins-infra-bot
    Author
    oleg_nenashev:
    • Original comment link
    • Raw content of original comment:

      JENKINS-47718 also deprecates the confusing User.get(String) API for cases when the user Creation is not expected

    JENKINS-47718 also deprecates the confusing User.get(String) API for cases when the user Creation is not expected

  6. jenkins-infra-bot commented on Nov 24, 2025

    @jenkins-infra-bot
    Author

    [Original relates_to from Jira: JENKINS-47718]

  7. removed
    bugFor changelog: Minor bug. Will be listed after features
    on Nov 25, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions