-
Notifications
You must be signed in to change notification settings - Fork 95
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Plugin is calling getRootUrlFromRequest from outside a request handling thread. #506
Comments
Looking at the oic-auth-plugin code, it appears the problem starts in org.jenkinsci.plugins.oic.OicSecurityRealm.java here:
The refreshExpiredToken method receives the HttpServletRequest as a parameter but does not use it when calling buildOidcClient, which in turn calls buildOAuthRedirectUrl, which calls ensureRootUrl, which calls getRootUrl(), which finally calls Jenkins.get().getRootUrlFromRequest(). The getRootUrlFromRequest method in the jenkins.model.Jenkins class automatically throws a java.lang.IllegalStateException if there is no HttpServletRequest in context, as shown below.
At first glance, it appears that the solution is to refactor the doFilter, handleTokenExpiration, refreshExpiredToken, buildOidcClient, buildOAuthRedirectUrl, ensureRootUrl and getRootUrl methods of the org.jenkinsci.plugins.oic.OicSecurityRealm class to accept and use an HttpServletRequest parameter. |
Displays where? If this displays on the UI then that would be strange as a UI request can not by it's nature not have a request. Is there anymore in the stacktrace? |
Unfortunately I am deployed in an airgapped environment with no direct Internet access and unable to readily copy-and-paste data here for security reasons, but here is the top of the call stack I manually entered from a stacktrace collected in the airgapped ennvironment.
You are right that there must be a request object for each request. If you follow through the above call stack you will see the problem is the call to getRootUrlFromRequest is from outside a request handling thread, most likely because the following method in the Jenkins class was never called:
An additional note is that the behavior only occurs sporadically, which smells like a concurrency issue. Clearly there are some cases where the StaplerRequest2 has not been initialized. |
Jenkins and plugins versions report
Environment
What Operating System are you using (both controller, and any agents involved in the problem)?
I'm using the bitnami jenkins container image: bitnami/jenkins:2.479.3-debian-r0
From inside the container image cat /etc/os-release confirms Debian 12 (bookworm)
Reproduction steps
Expected Results
The UI behaves as expected.
Actual Results
The message "A problem occurred whil processing the request" displays.
If you check the Jenkins logs and you will find the following:
java.lang.IllegalStateException: cannot call getRootUrlFromRequest from outisde a request handling thread
at jenkins.model.Jenkins.getRootUrlFromRequest(Jenkins.java:2574)
at PluginClassLoader for oic-auth//org.jenkinsci.plugins.oic.OicSecurityRealm.getRootUrl(OicSecurityRealm.java:1251)
Anything else?
I've tried Jenkins versions 2.479.1 and 2.479.3 with the same result. I verified that the oic-auth.jpi plugin is the latest available.
Are you interested in contributing a fix?
I don't know how much time I have available, but I can take a look and will give you a heads up if I find anything in the code. I believe the get getRootUrlFromRequest call is being made from outside the scope of the request context. The code may need to be refactored to address this.
The text was updated successfully, but these errors were encountered: