jenkinsci / docker-plugin

Jenkins cloud plugin that uses Docker
https://plugins.jenkins.io/docker-plugin/
MIT License
489 stars 319 forks source link

java.lang.reflect.InaccessibleObjectException: Unable to make field private static final long java.util.concurrent.atomic.AtomicBoolean.serialVersionUID accessible #905

Closed cobblermck closed 2 years ago

cobblermck commented 2 years ago

Jenkins and plugins versions report

Environment ```text Jenkins: 2.346.2 OS: Linux - 5.4.0-1086-azure --- Office-365-Connector:4.15.0 ace-editor:1.1 analysis-model-api:10.10.0 ant:1.11 antisamy-markup-formatter:2.7 apache-httpcomponents-client-4-api:4.5.13-1.0 artifactory:3.13.2 audit-trail:3.10 authentication-tokens:1.4 azure-app-service:1.0.2 azure-commons:1.1.3 azure-credentials:198.vf9c2fdfde55c azure-function:0.3.3 azure-sdk:61.v6a8af1f5f5b6 azure-vm-agents:9999-SNAPSHOT (private-05/24/2021 10:28-eryc02c) basic-branch-build-strategies:1.3.2 bitbucket:1.1.29 blueocean:1.24.8 blueocean-autofavorite:1.2.4 blueocean-bitbucket-pipeline:1.24.8 blueocean-commons:1.24.8 blueocean-config:1.24.8 blueocean-core-js:1.24.8 blueocean-dashboard:1.24.8 blueocean-display-url:2.4.1 blueocean-events:1.24.8 blueocean-git-pipeline:1.24.8 blueocean-github-pipeline:1.24.8 blueocean-i18n:1.24.8 blueocean-jwt:1.24.8 blueocean-personalization:1.24.8 blueocean-pipeline-api-impl:1.24.8 blueocean-pipeline-editor:1.24.8 blueocean-pipeline-scm-api:1.24.8 blueocean-rest:1.24.8 blueocean-rest-impl:1.24.8 blueocean-web:1.24.8 bootstrap4-api:4.6.0-3 bootstrap5-api:5.1.3-6 bouncycastle-api:2.25 branch-api:2.1044.v2c007e51b_87f build-timestamp:1.0.3 build-user-vars-plugin:1.8 caffeine-api:2.9.2-29.v717aac953ff3 checks-api:1.7.2 cloud-stats:0.27 cloudbees-bitbucket-branch-source:2.9.9 cloudbees-folder:6.714.v79e858ef76a_2 command-launcher:1.6 conditional-buildstep:1.4.1 config-file-provider:3.8.0 copyartifact:1.46.1 credentials:2.6.2 credentials-binding:1.27 cucumber-reports:5.7.1 data-tables-api:1.11.4-4 display-url-api:2.3.5 docker-commons:1.19 docker-java-api:3.1.5.2 docker-plugin:1.2.2 docker-workflow:1.26 durable-task:1.37 echarts-api:5.3.0-2 email-ext:2.83 embeddable-build-status:2.0.3 extended-choice-parameter:0.82 extended-read-permission:3.2 extensible-choice-parameter:1.7.0 external-monitor-job:1.7 favorite:2.3.3 font-awesome-api:6.0.0-1 forensics-api:1.12.0 generic-webhook-trigger:1.77 git:4.7.2 git-client:3.7.2 git-parameter:0.9.13 git-server:1.10 github:1.33.1 github-api:1.123 github-branch-source:2.10.2 gitlab-plugin:1.5.20 gradle:1.36 greenballs:1.15.1 handlebars:3.0.8 handy-uri-templates-2-api:2.1.8-1.0 htmlpublisher:1.25 http_request:1.11 ivy:2.1 jackson2-api:2.13.2.20220328-273.v11d70a_b_a_1a_52 jacoco:3.3.0 javadoc:1.6 javax-activation-api:1.2.0-2 javax-mail-api:1.6.2-5 jaxb:2.3.0 jdk-tool:1.5 jenkins-design-language:1.24.8 jira-steps:1.6.0 jjwt-api:0.11.2-9.c8b45b8bb173 jquery:1.12.4-1 jquery-detached:1.2.1 jquery3-api:3.6.0-2 jsch:0.1.55.2 junit:1.50 ldap:2.7 lockable-resources:2.11 mailer:408.vd726a_1130320 mapdb-api:1.0.9.0 mask-passwords:3.0 matrix-auth:2.6.7 matrix-project:1.20 maven-plugin:3.12 mercurial:2.15 mission-control-view:0.9.16 momentjs:1.1.1 monitoring:1.87.0 multibranch-build-strategy-extension:1.0.10 okhttp-api:3.14.9 pam-auth:1.6 parameterized-trigger:2.44 pipeline-build-step:2.17 pipeline-github-lib:1.0 pipeline-graph-analysis:1.11 pipeline-input-step:2.12 pipeline-milestone-step:1.3.2 pipeline-model-api:1.8.5 pipeline-model-definition:1.8.5 pipeline-model-extensions:1.8.5 pipeline-rest-api:2.19 pipeline-stage-step:2.5 pipeline-stage-tags-metadata:1.8.5 pipeline-stage-view:2.19 pipeline-utility-steps:2.8.0 plain-credentials:1.7 plugin-util-api:2.16.0 popper-api:1.16.1-2 popper2-api:2.11.5-1 postbuild-task:1.9 postbuildscript:3.1.0-369.vb_cc225753c4b_ prism-api:1.26.0-2 pubsub-light:1.16 resource-disposer:0.16 role-strategy:3.1.1 run-condition:1.5 scm-api:602.v6a_81757a_31d2 script-security:1145.vb_cf6cf6ed960 snakeyaml-api:1.29.1 sonar:2.13.1 sse-gateway:1.24 ssh-agent:1.24.1 ssh-credentials:1.19 ssh-slaves:1.33.0 ssh-steps:2.0.0 sshd:3.1.0 structs:318.va_f3ccb_729b_71 subversion:2.15.4 thinBackup:1.10 throttle-concurrents:2.3 timestamper:1.13 token-macro:293.v283932a_0a_b_49 trilead-api:1.0.13 uno-choice:2.5.6 uploaded1674241992762064703:??? uploaded3602274684500494963:??? uploaded553185394649542620:??? uploaded5882287038286726:??? uploaded707806167046363854:??? variant:1.4 veracode-scan:21.6.13.0 view-job-filters:2.3 warnings-ng:9.11.1 windows-slaves:1.8.1 workflow-aggregator:2.6 workflow-api:1143.v2d42f1e9dea_5 workflow-basic-steps:2.23 workflow-cps:2686.v7c37e0578401 workflow-cps-global-lib:570.v21311f4951f8 workflow-durable-task-step:2.39 workflow-job:1174.vdcb_d054cf74a_ workflow-multibranch:711.vdfef37cda_816 workflow-scm-step:2.13 workflow-step-api:622.vb_8e7c15b_c95a_ workflow-support:817.v58126df57338 ws-cleanup:0.39 ```

What Operating System are you using (both controller, and any agents involved in the problem)?

Ubuntu 20

Reproduction steps

Start a build which utilizes docker-plugin

Expected Results

A docker container is created, connected to, and job run on it

Actual Results

The job hangs forever. Looking at the Jenkins System log, I see the following over and over again:

Trying to run container for node mps-ubuntu-00000js6z985s from image: mck-mps-docker-registry-virtual.jfrog.io/mps-ubuntu:18.04
Jul 13, 2022 10:46:39 PM INFO com.nirima.jenkins.plugins.docker.DockerTemplate doProvisionNode
Started container ID 9f9023798eb3fa691e862a6fd0dae57ab46b57c5a7ea0b57dd8c72017e319525 for node mps-ubuntu-00000js6z985s from image: mck-mps-docker-registry-virtual.jfrog.io/mps-ubuntu:18.04
Jul 13, 2022 10:46:40 PM INFO com.nirima.jenkins.plugins.docker.utils.PortUtils$ConnectionCheckSSH executeOnce
SSH port is open on 10.15.164.57:49459
Jul 13, 2022 10:46:41 PM SEVERE com.nirima.jenkins.plugins.docker.DockerCloud$1 run
Error in provisioning; template='DockerTemplate{configVersion=2, labelString='mps-ubuntu', connector=DockerComputerSSHConnector{sshKeyStrategy=ManuallyConfiguredSSHKey{credentialsId='jenkins-container', sshHostKeyVerificationStrategy=hudson.plugins.sshslaves.verifiers.NonVerifyingKeyVerificationStrategy@7312f408}, port=22}, remoteFs='/home/jenkins', instanceCap=2, mode=EXCLUSIVE, retentionStrategy=com.nirima.jenkins.plugins.docker.strategy.DockerOnceRetentionStrategy@29, dockerTemplateBase=DockerTemplateBase{image='mck-mps-docker-registry-virtual.jfrog.io/mps-ubuntu:18.04', pullCredentialsId='6c2c6dee-7af0-4d77-ac39-1242d8171600', bindAllPorts=false, cpuPeriod=0, cpuQuota=0, privileged=false, tty=false}, removeVolumes=false, stopTimeout=10, pullStrategy=PULL_ALWAYS, pullTimeout=300, disabled=No, name='mps-ubuntu'}' for cloud='Docker Cloud West 01'
java.lang.reflect.InaccessibleObjectException: Unable to make field private static final long java.util.concurrent.atomic.AtomicBoolean.serialVersionUID accessible: module java.base does not "opens java.util.concurrent.atomic" to unnamed module @be35cd9
    at java.base/java.lang.reflect.AccessibleObject.checkCanSetAccessible(AccessibleObject.java:354)
    at java.base/java.lang.reflect.AccessibleObject.checkCanSetAccessible(AccessibleObject.java:297)
    at java.base/java.lang.reflect.Field.checkCanSetAccessible(Field.java:178)
    at java.base/java.lang.reflect.Field.setAccessible(Field.java:172)
    at com.thoughtworks.xstream.converters.reflection.FieldDictionary.buildDictionaryEntryForClass(FieldDictionary.java:176)
    at com.thoughtworks.xstream.converters.reflection.FieldDictionary.buildMap(FieldDictionary.java:142)
    at com.thoughtworks.xstream.converters.reflection.FieldDictionary.fieldsFor(FieldDictionary.java:80)
    at com.thoughtworks.xstream.converters.reflection.PureJavaReflectionProvider.visitSerializableFields(PureJavaReflectionProvider.java:167)
    at hudson.util.RobustReflectionConverter.doMarshal(RobustReflectionConverter.java:206)
    at hudson.util.RobustReflectionConverter.marshal(RobustReflectionConverter.java:163)
    at com.thoughtworks.xstream.core.AbstractReferenceMarshaller.convert(AbstractReferenceMarshaller.java:68)
    at com.thoughtworks.xstream.core.TreeMarshaller.convertAnother(TreeMarshaller.java:59)
    at com.thoughtworks.xstream.core.AbstractReferenceMarshaller$1.convertAnother(AbstractReferenceMarshaller.java:83)
    at hudson.util.RobustReflectionConverter.marshallField(RobustReflectionConverter.java:283)
    at hudson.util.RobustReflectionConverter$2.writeField(RobustReflectionConverter.java:270)
Caused: java.lang.RuntimeException: Failed to serialize io.jenkins.docker.DockerTransientNode#acceptingTasks for class io.jenkins.docker.DockerTransientNode
    at hudson.util.RobustReflectionConverter$2.writeField(RobustReflectionConverter.java:274)
    at hudson.util.RobustReflectionConverter$2.visit(RobustReflectionConverter.java:241)
    at com.thoughtworks.xstream.converters.reflection.PureJavaReflectionProvider.visitSerializableFields(PureJavaReflectionProvider.java:174)
    at hudson.util.RobustReflectionConverter.doMarshal(RobustReflectionConverter.java:226)
    at hudson.util.RobustReflectionConverter.marshal(RobustReflectionConverter.java:163)
    at com.thoughtworks.xstream.core.AbstractReferenceMarshaller.convert(AbstractReferenceMarshaller.java:68)
    at com.thoughtworks.xstream.core.TreeMarshaller.convertAnother(TreeMarshaller.java:59)
    at com.thoughtworks.xstream.core.TreeMarshaller.convertAnother(TreeMarshaller.java:44)
    at com.thoughtworks.xstream.core.TreeMarshaller.start(TreeMarshaller.java:83)
    at com.thoughtworks.xstream.core.AbstractTreeMarshallingStrategy.marshal(AbstractTreeMarshallingStrategy.java:37)
    at com.thoughtworks.xstream.XStream.marshal(XStream.java:1266)
    at com.thoughtworks.xstream.XStream.marshal(XStream.java:1255)
    at com.thoughtworks.xstream.XStream.toXML(XStream.java:1228)
    at hudson.XmlFile.write(XmlFile.java:213)
Caused: java.io.IOException
    at hudson.XmlFile.write(XmlFile.java:220)
    at jenkins.model.Nodes.persistNode(Nodes.java:183)
    at jenkins.model.Nodes.addNode(Nodes.java:148)
    at jenkins.model.Jenkins.addNode(Jenkins.java:2208)
    at com.nirima.jenkins.plugins.docker.DockerCloud.robustlyAddNodeToJenkins(DockerCloud.java:445)
    at com.nirima.jenkins.plugins.docker.DockerCloud.access$000(DockerCloud.java:68)
    at com.nirima.jenkins.plugins.docker.DockerCloud$1.run(DockerCloud.java:381)
    at jenkins.util.ContextResettingExecutorService$1.run(ContextResettingExecutorService.java:28)
    at jenkins.security.ImpersonatingExecutorService$1.run(ImpersonatingExecutorService.java:68)
    at java.base/java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:539)
    at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
    at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1136)
    at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:635)
    at java.base/java.lang.Thread.run(Thread.java:833)

Anything else?

No response

cobblermck commented 2 years ago

I think this was just caused by weird plugin versions.

cobblermck commented 2 years ago

Thought I was past this but I'm not. Sorry - long night already. I installed the 1.2.10 snapshot and it's behaving the same way as 1.2.3 for me at the moment.

cobblermck commented 2 years ago

jdk17 issue

pjdarton commented 2 years ago

While it is true that there is a AtomicBoolean field called acceptingTasks in DockerTransientNode.java, I don't believe that using such a "normal" (serializable and built-in-to-Java) class is unreasonable here. It's reasonable to expect this kind of usage to "just work".

So, while I can see that there's a problem in this scenario, I don't think that it would be correct to change the docker-plugin code - if you're seeing this issue here then there's probably a lot of other things that won't be working either, and the "proper fix" would be to fix the hudson.XmlFile.write method (or the methods it calls) so it works on Java17, e.g. by updating com.thoughtworks.xstream.converters.reflection.FieldDictionary to one that is compatible with Java17. i.e. this is likely a symptom of a wider jdk17 malaise.

If you're desperate for a workaround to tide you over until that wider issue is fixed then by all means submit a PR ... but unless it's dead simple and "obviously OK" it's unlikely to be merged into the official release (as I don't want to pollute this codebase with workarounds for bugs elsewhere).

cobblermck commented 2 years ago

Well said and I agree. This was occurring in a rather unhealthy environment last night. I thought I closed it with my jdk17 comment tbh

shawngmc commented 2 years ago

I'm running into what I think is the same issue; what is the long term fix for this?

Jenkins Core project doesn't have an issue tracker in the GH project and I don't see anything in the Jenkins Jira. The closest I see is https://issues.jenkins.io/browse/JENKINS-68071, but while the error is the same it's a completely different functionality.

basil commented 2 years ago

what is the long term fix for this?

I opened https://github.com/x-stream/xstream/issues/308 to discuss the long-term fix with the X-Stream developers.

basil commented 2 years ago

A month later, my pull request to XStream remains unacknowledged, so I integrated https://github.com/jenkinsci/jenkins/pull/7270 toward 2.375. This will provide support for serializing AtomicBoolean on Java 17, resolving the immediate issue, but serializing classes in the java.util.concurrent package is still not something we recommend: the implementation and representation of these concurrent types is more complex and prone to error, and we instead suggest declaring the persisted field to be of some simpler type (e.g., boolean) and using a transient field for an in-memory representation of a complex type. Though this issue can remain closed, I would ask that a new code cleanup task be filed to cover moving this plugin off AtomicBoolean at some point in time in the future: while the immediate pain will be resolved in 2.375 by https://github.com/jenkinsci/jenkins/pull/7270, in the long term this plugin would be less fragile if it used a simpler type.

jglick commented 2 years ago

See https://github.com/jenkinsci/workflow-cps-plugin/pull/515 for example.