Uploaded image for project: 'Jenkins'
  1. Jenkins
  2. JENKINS-55945

Got IllegalStateException while restart Jenkins

    • Jenkins 2.185

      Hi oleg_nenashev 
      I'm using Jenkins version 2.162
      When I restart jenkins using /restart command or after plugin installation I got the following error at Jenkins restart page:

      Stack tracejava.lang.IllegalStateException: Expected 1 instance of hudson.model.User$AllUsers but got 0
      	at hudson.ExtensionList.lookupSingleton(ExtensionList.java:450)
      	at hudson.model.User$AllUsers.getInstance(User.java:1084)
      	at hudson.model.User$AllUsers.get(User.java:1102)
      	at hudson.model.User$AllUsers.access$100(User.java:1065)
      	at hudson.model.User.getOrCreateById(User.java:521)
      	at hudson.model.User.getById(User.java:619)
      	at hudson.security.HttpSessionContextIntegrationFilter2.hasInvalidSessionSeed(HttpSessionContextIntegrationFilter2.java:87)
      	at hudson.security.HttpSessionContextIntegrationFilter2.doFilter(HttpSessionContextIntegrationFilter2.java:60)
      	at hudson.security.ChainedServletFilter$1.doFilter(ChainedServletFilter.java:87)
      	at hudson.security.ChainedServletFilter.doFilter(ChainedServletFilter.java:90)
      	at hudson.security.HudsonFilter.doFilter(HudsonFilter.java:171)
      	at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1642)
      	at org.kohsuke.stapler.compression.CompressionFilter.doFilter(CompressionFilter.java:49)
      	at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1642)
      	at hudson.util.CharacterEncodingFilter.doFilter(CharacterEncodingFilter.java:82)
      	at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1642)
      	at org.kohsuke.stapler.DiagnosticThreadNameFilter.doFilter(DiagnosticThreadNameFilter.java:30)
      	at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1642)
      	at org.eclipse.jetty.servlet.ServletHandler.doHandle(ServletHandler.java:533)
      	at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:146)
      	at org.eclipse.jetty.security.SecurityHandler.handle(SecurityHandler.java:524)
      	at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:132)
      	at org.eclipse.jetty.server.handler.ScopedHandler.nextHandle(ScopedHandler.java:257)
      	at org.eclipse.jetty.server.session.SessionHandler.doHandle(SessionHandler.java:1595)
      	at org.eclipse.jetty.server.handler.ScopedHandler.nextHandle(ScopedHandler.java:255)
      	at org.eclipse.jetty.server.handler.ContextHandler.doHandle(ContextHandler.java:1340)
      	at org.eclipse.jetty.server.handler.ScopedHandler.nextScope(ScopedHandler.java:203)
      	at org.eclipse.jetty.servlet.ServletHandler.doScope(ServletHandler.java:473)
      	at org.eclipse.jetty.server.session.SessionHandler.doScope(SessionHandler.java:1564)
      	at org.eclipse.jetty.server.handler.ScopedHandler.nextScope(ScopedHandler.java:201)
      	at org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandler.java:1242)
      	at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:144)
      	at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:132)
      	at org.eclipse.jetty.server.Server.handle(Server.java:503)
      	at org.eclipse.jetty.server.HttpChannel.handle(HttpChannel.java:364)
      	at org.eclipse.jetty.server.HttpConnection.onFillable(HttpConnection.java:260)
      	at org.eclipse.jetty.io.AbstractConnection$ReadCallback.succeeded(AbstractConnection.java:305)
      	at org.eclipse.jetty.io.FillInterest.fillable(FillInterest.java:103)
      	at org.eclipse.jetty.io.ChannelEndPoint$2.run(ChannelEndPoint.java:118)
      	at org.eclipse.jetty.util.thread.strategy.EatWhatYouKill.runTask(EatWhatYouKill.java:333)
      	at org.eclipse.jetty.util.thread.strategy.EatWhatYouKill.doProduce(EatWhatYouKill.java:310)
      	at org.eclipse.jetty.util.thread.strategy.EatWhatYouKill.tryProduce(EatWhatYouKill.java:168)
      	at org.eclipse.jetty.util.thread.strategy.EatWhatYouKill.run(EatWhatYouKill.java:126)
      	at org.eclipse.jetty.util.thread.ReservedThreadExecutor$ReservedThread.run(ReservedThreadExecutor.java:366)
      	at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:765)
      	at org.eclipse.jetty.util.thread.QueuedThreadPool$2.run(QueuedThreadPool.java:683)
      	at java.lang.Thread.run(Thread.java:748)
      

      As I see frontend part scripts/loading.js:53 sent GET request to server URL and got 500 code. 

      The normal behaviour of  loading.js:41 should get 503 code from the server

          [JENKINS-55945] Got IllegalStateException while restart Jenkins

          Jeff Thompson added a comment -

          simontunnat, as I mentioned above, you can read about the LTS releases, including backports, at https://jenkins.io/download/lts/

          Jeff Thompson added a comment - simontunnat , as I mentioned above, you can read about the LTS releases, including backports, at  https://jenkins.io/download/lts/

          Lübbe Onken added a comment - - edited

          The issue is not yet resolved.

          We have exactly the same problem as supjac in #comment-371811.

          Just updated Jenkins from 2.219 to 2.220, Windows Server 2016 and a dedicated jenkins user.

          Jenkins gets into this infinite loop when we try to restart it from the web frontend.
          The jenkins service always has to be restarted manually after a jenkins or plugin update.

          No problems restarting jenkins from the web frontend when it runs as system user directly after the installation.

           

          2020-02-11 10:38:05.853+0000 [id=770] INFO jenkins.model.Jenkins#cleanUp: Stopping Jenkins
          2020-02-11 10:38:05.868+0000 [id=770] INFO jenkins.model.Jenkins$18#onAttained: Started termination
          2020-02-11 10:38:05.946+0000 [id=770] INFO jenkins.model.Jenkins$18#onAttained: Completed termination
          2020-02-11 10:38:05.946+0000 [id=770] INFO jenkins.model.Jenkins#_cleanUpDisconnectComputers: Starting node disconnection
          2020-02-11 10:38:05.962+0000 [id=770] INFO jenkins.model.Jenkins#_cleanUpShutdownPluginManager: Stopping plugin manager
          2020-02-11 10:38:05.962+0000 [id=770] INFO jenkins.model.Jenkins#_cleanUpPersistQueue: Persisting build queue
          2020-02-11 10:38:05.979+0000 [id=770] INFO jenkins.model.Jenkins#_cleanUpAwaitDisconnects: Waiting for node disconnection completion
          2020-02-11 10:38:05.979+0000 [id=770] INFO jenkins.model.Jenkins#cleanUp: Jenkins stopped
          2020-02-11 10:38:06.103+0000 [id=12] WARNING h.s.HttpSessionContextIntegrationFilter2#hasInvalidSessionSeed: Encountered IllegalStateException trying to get a user. System init may not have completed yet. Invalidating user session.
          2020-02-11 10:38:11.133+0000 [id=603] WARNING h.s.HttpSessionContextIntegrationFilter2#hasInvalidSessionSeed: Encountered IllegalStateException trying to get a user. System init may not have completed yet. Invalidating user session.
          2020-02-11 10:38:16.164+0000 [id=632] WARNING h.s.HttpSessionContextIntegrationFilter2#hasInvalidSessionSeed: Encountered IllegalStateException trying to get a user. System init may not have completed yet. Invalidating user session.
          2020-02-11 10:38:21.193+0000 [id=12] WARNING h.s.HttpSessionContextIntegrationFilter2#hasInvalidSessionSeed: Encountered IllegalStateException trying to get a user. System init may not have completed yet. Invalidating user session.
          2020-02-11 10:38:26.211+0000 [id=603] WARNING h.s.HttpSessionContextIntegrationFilter2#hasInvalidSessionSeed: Encountered IllegalStateException trying to get a user. System init may not have completed yet. Invalidating user session.

          Lübbe Onken added a comment - - edited The issue is not yet resolved. We have exactly the same problem as supjac in #comment-371811. Just updated Jenkins from 2.219 to 2.220, Windows Server 2016 and a dedicated jenkins user. Jenkins gets into this infinite loop when we try to restart it from the web frontend. The jenkins service always has to be restarted manually after a jenkins or plugin update. No problems restarting jenkins from the web frontend when it runs as system user directly after the installation.   2020-02-11 10:38:05.853+0000 [id=770] INFO jenkins.model.Jenkins#cleanUp: Stopping Jenkins 2020-02-11 10:38:05.868+0000 [id=770] INFO jenkins.model.Jenkins$18#onAttained: Started termination 2020-02-11 10:38:05.946+0000 [id=770] INFO jenkins.model.Jenkins$18#onAttained: Completed termination 2020-02-11 10:38:05.946+0000 [id=770] INFO jenkins.model.Jenkins#_cleanUpDisconnectComputers: Starting node disconnection 2020-02-11 10:38:05.962+0000 [id=770] INFO jenkins.model.Jenkins#_cleanUpShutdownPluginManager: Stopping plugin manager 2020-02-11 10:38:05.962+0000 [id=770] INFO jenkins.model.Jenkins#_cleanUpPersistQueue: Persisting build queue 2020-02-11 10:38:05.979+0000 [id=770] INFO jenkins.model.Jenkins#_cleanUpAwaitDisconnects: Waiting for node disconnection completion 2020-02-11 10:38:05.979+0000 [id=770] INFO jenkins.model.Jenkins#cleanUp: Jenkins stopped 2020-02-11 10:38:06.103+0000 [id=12] WARNING h.s.HttpSessionContextIntegrationFilter2#hasInvalidSessionSeed: Encountered IllegalStateException trying to get a user. System init may not have completed yet. Invalidating user session. 2020-02-11 10:38:11.133+0000 [id=603] WARNING h.s.HttpSessionContextIntegrationFilter2#hasInvalidSessionSeed: Encountered IllegalStateException trying to get a user. System init may not have completed yet. Invalidating user session. 2020-02-11 10:38:16.164+0000 [id=632] WARNING h.s.HttpSessionContextIntegrationFilter2#hasInvalidSessionSeed: Encountered IllegalStateException trying to get a user. System init may not have completed yet. Invalidating user session. 2020-02-11 10:38:21.193+0000 [id=12] WARNING h.s.HttpSessionContextIntegrationFilter2#hasInvalidSessionSeed: Encountered IllegalStateException trying to get a user. System init may not have completed yet. Invalidating user session. 2020-02-11 10:38:26.211+0000 [id=603] WARNING h.s.HttpSessionContextIntegrationFilter2#hasInvalidSessionSeed: Encountered IllegalStateException trying to get a user. System init may not have completed yet. Invalidating user session.

          luebbe is right - we have the same issue where jenkins.err.log shows:

          Encountered IllegalStateException trying to get a user. System init may not have completed yet. Invalidating user session.

          We use Jenkins 2.255 on Windows Server 2016

          Niels Kristian Jensen added a comment - luebbe is right - we have the same issue where jenkins.err.log shows: Encountered IllegalStateException trying to get a user. System init may not have completed yet. Invalidating user session. We use Jenkins 2.255 on Windows Server 2016

          ethorsa added a comment -

          I can confirm the problem on windows hosted Jenkins v2.235.5.

          ethorsa added a comment - I can confirm the problem on windows hosted Jenkins v2.235.5.

          Niels Kristian Jensen added a comment - - edited

          The issue is still there in Jenkins 2.249.1 on Windows Server 2019 and a dedicated jenkins user.

          Niels Kristian Jensen added a comment - - edited The issue is still there in Jenkins 2.249.1 on Windows Server 2019 and a dedicated jenkins user.

          Alex added a comment -

          I got the same flood of errors on Jenkins 2.263.1

          WARNING h.s.HttpSessionContextIntegrationFilter2#hasInvalidSessionSeed: Encountered IllegalStateException trying to get a user. System init may not have completed yet. Invalidating user session.
          

          Took a look at jenkins.wrapper.log and noticed

          2021-01-11 00:37:42,243 FATAL - WMI Operation failure: AccessDenied
          WMI.WmiException: AccessDenied
             at WMI.WmiRoot.BaseHandler.CheckError(ManagementBaseObject result)
             at WMI.WmiRoot.InstanceHandler.Invoke(Object proxy, MethodInfo method, Object[] arguments)
             at winsw.WrapperService.<Run>g__Restart|33_5(<>c__DisplayClass33_0& )
             at winsw.WrapperService.Run(String[] _args, ServiceDescriptor descriptor)
             at winsw.WrapperService.Main(String[] args)
          

          So it looks like the Web UI /restart endpoint is trying to actually restart a Windows service, for which it does not have permissions if running as a limited user. To fix this, it is possible to run Jenkins as a member of Power Users or Administrators group, but I chose to grant permissions for restarting only the Jenkins service.

          Using setacl, to view permissions:
          SetACL.exe -on jenkins -ot srv -actn list
          To grant service restart permissions ('jenkins' is the name of the service and 'domain\user' should be replaced with actual values):
          SetACL.exe -on jenkins -ot srv -actn ace -ace "n:domain\user;p:start_stop;m:grant"

          Tried it, and it worked for me.

          Alex added a comment - I got the same flood of errors on Jenkins 2.263.1 WARNING h.s.HttpSessionContextIntegrationFilter2#hasInvalidSessionSeed: Encountered IllegalStateException trying to get a user. System init may not have completed yet. Invalidating user session. Took a look at jenkins.wrapper.log and noticed 2021-01-11 00:37:42,243 FATAL - WMI Operation failure: AccessDenied WMI.WmiException: AccessDenied at WMI.WmiRoot.BaseHandler.CheckError(ManagementBaseObject result) at WMI.WmiRoot.InstanceHandler.Invoke(Object proxy, MethodInfo method, Object[] arguments) at winsw.WrapperService.<Run>g__Restart|33_5(<>c__DisplayClass33_0& ) at winsw.WrapperService.Run(String[] _args, ServiceDescriptor descriptor) at winsw.WrapperService.Main(String[] args) So it looks like the Web UI /restart endpoint is trying to actually restart a Windows service, for which it does not have permissions if running as a limited user. To fix this, it is possible to run Jenkins as a member of Power Users or Administrators group, but I chose to grant permissions for restarting only the Jenkins service. Using setacl , to view permissions: SetACL.exe -on jenkins -ot srv -actn list To grant service restart permissions ('jenkins' is the name of the service and 'domain\user' should be replaced with actual values): SetACL.exe -on jenkins -ot srv -actn ace -ace "n:domain\user;p:start_stop;m:grant" Tried it, and it worked for me.

          Niels Kristian Jensen added a comment - We no longer have the issue, after applying the fix seen here: https://issues.jenkins.io/browse/JENKINS-50219?focusedCommentId=338697&page=com.atlassian.jira.plugin.system.issuetabpanels%3Acomment-tabpanel#comment-338697

          ethorsa added a comment -

          nkjensen unfortunately this didn't help in my case, I still get an IllegalStateException and stuck Jenkins.

          ethorsa added a comment - nkjensen  unfortunately this didn't help in my case, I still get an IllegalStateException and stuck Jenkins.

          Lots of discussion about this on Windows. Are people seeing this on Linux?

          Also, below is our exact error. It has the same Expected instance syntax, but it isn't referencing the AllUsers, so I wonder if this is something different.

          java.lang.IllegalStateException: Expected 1 instance of jenkins.security.s2m.AdminWhitelistRule but got 0
          at hudson.ExtensionList.lookupSingleton(ExtensionList.java:451)
          at io.jenkins.plugins.casc.core.AdminWhitelistRuleConfigurator.instance(AdminWhitelistRuleConfigurator.java:59)
          at io.jenkins.plugins.casc.core.AdminWhitelistRuleConfigurator.instance(AdminWhitelistRuleConfigurator.java:42)
          at io.jenkins.plugins.casc.BaseConfigurator.check(BaseConfigurator.java:286)
          at io.jenkins.plugins.casc.BaseConfigurator.configure(BaseConfigurator.java:351)
          at io.jenkins.plugins.casc.BaseConfigurator.check(BaseConfigurator.java:287)
          at io.jenkins.plugins.casc.ConfigurationAsCode.lambda$checkWith$8(ConfigurationAsCode.java:777)
          at io.jenkins.plugins.casc.ConfigurationAsCode.invokeWith(ConfigurationAsCode.java:713)
          at io.jenkins.plugins.casc.ConfigurationAsCode.checkWith(ConfigurationAsCode.java:777)
          at io.jenkins.plugins.casc.ConfigurationAsCode.configureWith(ConfigurationAsCode.java:762)
          at io.jenkins.plugins.casc.ConfigurationAsCode.configureWith(ConfigurationAsCode.java:638)
          at io.jenkins.plugins.casc.ConfigurationAsCode.configure(ConfigurationAsCode.java:307)
          at io.jenkins.plugins.casc.ConfigurationAsCode.init(ConfigurationAsCode.java:299)

          Doug Whitfield added a comment - Lots of discussion about this on Windows. Are people seeing this on Linux? Also, below is our exact error. It has the same Expected instance syntax, but it isn't referencing the AllUsers, so I wonder if this is something different. java.lang.IllegalStateException: Expected 1 instance of jenkins.security.s2m.AdminWhitelistRule but got 0 at hudson.ExtensionList.lookupSingleton(ExtensionList.java:451) at io.jenkins.plugins.casc.core.AdminWhitelistRuleConfigurator.instance(AdminWhitelistRuleConfigurator.java:59) at io.jenkins.plugins.casc.core.AdminWhitelistRuleConfigurator.instance(AdminWhitelistRuleConfigurator.java:42) at io.jenkins.plugins.casc.BaseConfigurator.check(BaseConfigurator.java:286) at io.jenkins.plugins.casc.BaseConfigurator.configure(BaseConfigurator.java:351) at io.jenkins.plugins.casc.BaseConfigurator.check(BaseConfigurator.java:287) at io.jenkins.plugins.casc.ConfigurationAsCode.lambda$checkWith$8(ConfigurationAsCode.java:777) at io.jenkins.plugins.casc.ConfigurationAsCode.invokeWith(ConfigurationAsCode.java:713) at io.jenkins.plugins.casc.ConfigurationAsCode.checkWith(ConfigurationAsCode.java:777) at io.jenkins.plugins.casc.ConfigurationAsCode.configureWith(ConfigurationAsCode.java:762) at io.jenkins.plugins.casc.ConfigurationAsCode.configureWith(ConfigurationAsCode.java:638) at io.jenkins.plugins.casc.ConfigurationAsCode.configure(ConfigurationAsCode.java:307) at io.jenkins.plugins.casc.ConfigurationAsCode.init(ConfigurationAsCode.java:299)

          ethorsa added a comment - - edited

          I'm having the same problem on a RHEL Jenkins:

          java.lang.IllegalStateException: Expected 1 instance of jenkins.security.s2m.AdminWhitelistRule but got 0
          	at hudson.ExtensionList.lookupSingleton(ExtensionList.java:452)
          	at io.jenkins.plugins.casc.core.AdminWhitelistRuleConfigurator.instance(AdminWhitelistRuleConfigurator.java:59)
          	at io.jenkins.plugins.casc.core.AdminWhitelistRuleConfigurator.instance(AdminWhitelistRuleConfigurator.java:42)
          	at io.jenkins.plugins.casc.BaseConfigurator.check(BaseConfigurator.java:285)
          	at io.jenkins.plugins.casc.BaseConfigurator.configure(BaseConfigurator.java:350)
          	at io.jenkins.plugins.casc.BaseConfigurator.check(BaseConfigurator.java:286)
          	at io.jenkins.plugins.casc.ConfigurationAsCode.lambda$checkWith$8(ConfigurationAsCode.java:776)
          	at io.jenkins.plugins.casc.ConfigurationAsCode.invokeWith(ConfigurationAsCode.java:712)
          	at io.jenkins.plugins.casc.ConfigurationAsCode.checkWith(ConfigurationAsCode.java:776)
          	at io.jenkins.plugins.casc.ConfigurationAsCode.configureWith(ConfigurationAsCode.java:761)
          	at io.jenkins.plugins.casc.ConfigurationAsCode.configureWith(ConfigurationAsCode.java:637)
          	at io.jenkins.plugins.casc.ConfigurationAsCode.configure(ConfigurationAsCode.java:306)
          	at io.jenkins.plugins.casc.ConfigurationAsCode.init(ConfigurationAsCode.java:298)

          ethorsa added a comment - - edited I'm having the same problem on a RHEL Jenkins: java.lang.IllegalStateException: Expected 1 instance of jenkins.security.s2m.AdminWhitelistRule but got 0 at hudson.ExtensionList.lookupSingleton(ExtensionList.java:452) at io.jenkins.plugins.casc.core.AdminWhitelistRuleConfigurator.instance(AdminWhitelistRuleConfigurator.java:59) at io.jenkins.plugins.casc.core.AdminWhitelistRuleConfigurator.instance(AdminWhitelistRuleConfigurator.java:42) at io.jenkins.plugins.casc.BaseConfigurator.check(BaseConfigurator.java:285) at io.jenkins.plugins.casc.BaseConfigurator.configure(BaseConfigurator.java:350) at io.jenkins.plugins.casc.BaseConfigurator.check(BaseConfigurator.java:286) at io.jenkins.plugins.casc.ConfigurationAsCode.lambda$checkWith$8(ConfigurationAsCode.java:776) at io.jenkins.plugins.casc.ConfigurationAsCode.invokeWith(ConfigurationAsCode.java:712) at io.jenkins.plugins.casc.ConfigurationAsCode.checkWith(ConfigurationAsCode.java:776) at io.jenkins.plugins.casc.ConfigurationAsCode.configureWith(ConfigurationAsCode.java:761) at io.jenkins.plugins.casc.ConfigurationAsCode.configureWith(ConfigurationAsCode.java:637) at io.jenkins.plugins.casc.ConfigurationAsCode.configure(ConfigurationAsCode.java:306) at io.jenkins.plugins.casc.ConfigurationAsCode.init(ConfigurationAsCode.java:298)

            jthompson Jeff Thompson
            artem_fedorov Artem Fedorov
            Votes:
            17 Vote for this issue
            Watchers:
            30 Start watching this issue

              Created:
              Updated: