Skip to content

Intermittent NoClassDefFoundError: com/mongodb/internal/binding/ReferenceCounted #43290

Closed as not planned

Description

@Osmyslitelny

Introduction:
Before, I created an issue at spring-data-mongodb, but they recommended creating an issue for spring boot. Therefore, I copied the issue and created a new one in this repository.

Context:
We have scheduled services (jobs) that run multiple times a day. However, there is an issue where 1-3 runs per day fail with an error. All other runs are problem-free. Therefore, the error seems blinked.

Environment:

  1. We run these services using an docker image on Kubernetes.
  2. We connect to AWS DocumentDB.

Versions:
I think the main dependencies are Spring and related MongoDB libraries (such as mongo-driver). We obtain these dependencies through spring-boot-dependencies. Also, every spring version have different mongo related lib versions. We have tested them with different versions:

  1. spring 3.3.2 - no issues (or we never catch them)
  2. spring 3.3.4 - error occurs
  3. spring 3.3.5 - error occurs
  4. spring 3.4.0 - error occurs

Verification:
Since the issue is not consistent, we have examined the logs and checked for common causes such as missing classpath or empty BOOT-INF data and etc. Everything appears correct (and most of the runs are successful).

Error full stacktrace:
trace.txt

Notes:

  1. At different versions, sometimes we encounter a NoClassDefFoundError with other com/mongodb classes.
  2. Mongo FAQ that related to issue but looks like everything at our sine is correct. That why was decided that problem could be on spring side.
  3. Local Integration test + mongo testcontainer (not AWS DocumentDB) never get error.
  4. Maybe something related with 38611

Activity

  1. added
    status: waiting-for-triage
    on Nov 26, 2024
  2. wilkinsona commented on Nov 26, 2024

    @wilkinsona
    Member

    Thanks for the report.

    There certainly appears to be some similarity with #38611, but in this case it seems that the failure's occurring during startup and on the main thread. The problem in #38611 was occurring off the main thread and only when it had been interrupted. Unfortunately, without a way to reproduce the failure, I don't think we'll be able to diagnose the problem and either fix it or determine that it has an external cause.

    You could try using the classic loader implementation to see if that makes a difference. The new loader was introduced in Spring Boot 3.2.0 so, given that 3.3.2 works, it may not make a difference. It would also be interesting to know if the problem occurs with 3.3.3 as that would narrow down the differences between a working version and a failing version.

    Beyond that, I think we're really going to need a minimal sample that reproduces the problem to make any progress here.

  3. added
    status: waiting-for-feedback
    on Nov 26, 2024
  4. changed the title [-]Blinker NoClassDefFoundError: com/mongodb/internal/binding/ReferenceCounted[/-] [+]Intermittent NoClassDefFoundError: com/mongodb/internal/binding/ReferenceCounted[/+] on Nov 26, 2024
  5. Osmyslitelny commented on Nov 27, 2024

    @Osmyslitelny
    Author

    We tried using the classic loader on Spring 3.4.0 with a cron job set to run every 5 minutes. In the past 24 hours, we haven't had any failures, which is better than our usual rate of around 3 failures. Next, we will test version 3.3.3 without the classic loader for the next 24 hours, and also continue running the job without the classic loader for 48 hours to further evaluate its result.

    Unfortunately, I have no idea how to reproduce the failure because when you get 3 failures at day with this (5 min) schedule there is no idea what to do to reproduce that or catch.

    Tomorrow, I will update the information regarding 3.3.3. If you have any ideas on how to reproduce or expand the logs, or any other suggestions, please feel free to share them.

  6. added
    status: feedback-provided
    and removed
    status: waiting-for-feedback
    on Nov 27, 2024
  7. Osmyslitelny commented on Nov 28, 2024

    @Osmyslitelny
    Author

    We checked other version and current data is:

    spring 3.3.2 - no issues (or we never catch them)
    spring 3.3.3 - no issues (or we never catch them)
    spring 3.3.4 - error occurs
    spring 3.3.5 - error occurs
    spring 3.4.0 - error occurs
    spring 3.4.0 with classic loader - no issues (or we never catch them)

    If its also needed we use amazoncorretto:21.0.5

  8. wilkinsona commented on Nov 28, 2024

    @wilkinsona
    Member

    Thanks for the additional details.

    Looking more closely at the original stack trace, I've noticed a couple of things:

    1. A MultiServerCluster is being created
    2. The failure's occurring beneath com.mongodb.internal.Locks.withInterruptibleLock which casts some doubt on the theory that thread interruption is the cause

    1 requires some non-default configuration of Mongo. Please share that configuration with us.

    For 2, if I call Thread.currentThread.interrupt() before Mongo client's created, it quickly fails with a com.mongodb.MongoInterruptedException. If I, through the debugger, interrupt the thread once the lock has been taken, creating of the cluster succeeds without any class loading problems. I won't discount thread interruption completely at this point, but it is looking unlikely so we need some other avenues to explore.

    The loader can be configured to output some debug information (-Dloader.debug=true). It could be informative to compare this output from a run that succeeds and a run that fails. The two runs should be with the exact same binary so that all of the information about the positions of files in the archive and their sizes remains constant. Could you please gather this information and share it with us?

  9. added
    status: waiting-for-feedback
    and removed
    status: feedback-provided
    on Nov 28, 2024
  10. Osmyslitelny commented on Dec 2, 2024

    @Osmyslitelny
    Author

    I will collect all the mentioned information on various versions to compare. The error hasn't happened again in the last few days, but please don't close the issues for now. Once I have all the required logs, I will update the thread.

  11. added
    status: feedback-provided
    and removed
    status: waiting-for-feedback
    on Dec 2, 2024
  12. removed
    status: feedback-provided
    on Dec 2, 2024
  13. 15 remaining items

  14. wilkinsona commented on Dec 12, 2024

    @wilkinsona
    Member

    Sorry, I don't know why that would be. The passed logs should that output from the beginning of start up can be produced successfully. If I were to guess, I'd guess that something in the pod is limiting or tailing the output, perhaps only once it has reached a certain length.

  15. added
    status: waiting-for-feedback
    and removed
    status: feedback-provided
    on Dec 12, 2024
  16. spring-projects-issues commented on Dec 19, 2024

    @spring-projects-issues
    Collaborator

    If you would like us to look at this issue, please provide the requested information. If the information is not provided within the next 7 days this issue will be closed.

  17. added
    status: feedback-reminder
    on Dec 19, 2024
  18. Osmyslitelny commented on Dec 26, 2024

    @Osmyslitelny
    Author

    We found the full logs, but unfortunately, we couldn't capture the failure with debug information at this time (7 days 24/7 test period). The additional log output delay provided enough time to prevent the issue from being reproduced. Therefore, we only have full logs for the successful case. A potential proposal regarding this behavior was made earlier.

  19. added
    status: feedback-provided
    and removed
    status: waiting-for-feedback
    status: feedback-reminder
    on Dec 26, 2024
  20. skurzbac commented on Jan 20, 2025

    @skurzbac

    We also seem to hit this issue with MongoDB and Spring Boot 3.4.0 (NoClassDefFoundError in MongoDB management thread during application start-up). The root cause is "Zip file closed". Currently, we are evaluating if the CLASSIC loader implementation works around the problem. Capturing loader.debug logs in the error case is an effort we have not yet made.

  21. Osmyslitelny commented on Feb 20, 2025

    @Osmyslitelny
    Author

    We still believe it is important to identify the root cause and fix it, but we have found a "default available" option that we are using as a workaround.
    management.endpoint.health.group.liveness.include=livenessstate,mongo

  22. wilkinsona commented on Apr 16, 2025

    @wilkinsona
    Member

    Unfortunately, I don't think we'll be able to make any progress on this one without seeing the logs from the loader and comparing the success and failure cases. I'm going to close this one for now as it isn't actionable. We can re-open it should the logs or a reproducer become available.

  23. removed
    status: waiting-for-triage
    status: feedback-provided
    on Apr 16, 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

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions