Repository navigation
Description
We observe intermittent failures at application startup using this combination of dependencies:
- Spring Boot 4.0.6
- MongoDB Java driver 5.8.0
- Elastic APM Java Agent 1.56.0
It manifests as a
NoClassDefFoundError: com/mongodb/internal/connection/InternalStreamConnection by all of the MongoDB monitor threads that initially try to establish a connection to our MongoDB Atlas cluster.
The same issue happens with Spring Boot 3.5.X and can be resolved by using the LoaderImplementation.CLASSIC. This workaround is no longer available starting with Boot 4. We also had success by
- unpacking the affected driver JARs using Gradle (
requiresUnpack("**/mongodb-driver-core-*.jar")) - disabling the APM agent entirely
- disabling the
mongodbinstrumentation of the APM agent
An (AI generated) reproducer can be found here: https://github.com/janjanneck7777/springboot-loader-race-repro. Run it using ./capture-diagnostics.sh. On my machine the bug occurred in around 1 of 25 startups.
We are aware that the APM agent declares support for Boot 4 as experimental. That being said: The same (or at least very similar) bug occurred using Boot 3 with the new loader. We have no issues when using the classic loader, suggesting there might be something that could be handled better in the new loader.
See also: #43290
I attached the output of the reproducer to this ticket.
Main log output
[0.220s][info][jfr,startup] Started recording 1. No limit specified, using maxsize=250MB as default.
[0.220s][info][jfr,startup]
[0.220s][info][jfr,startup] Use jcmd 10988 JFR.dump name=repro to copy recording data to file.
WARNING: A terminally deprecated method in sun.misc.Unsafe has been called
WARNING: sun.misc.Unsafe::arrayBaseOffset has been called by com.lmax.disruptor.RingBufferFields (file:/private/var/folders/9r/mrxrn12567v24xty0cwy8y000000gp/T/elastic-apm-agent-8c1369c2fd16ed4842b88ae2f442d336-4595ce678bfe3a3420ada95356bc85c2.jar)
WARNING: Please consider reporting this to the maintainers of class com.lmax.disruptor.RingBufferFields
WARNING: sun.misc.Unsafe::arrayBaseOffset will be removed in a future release
APM agent: attached via ElasticApmAttacher.attach()
Connecting MongoClient to mongodb://192.0.2.1:27017,192.0.2.2:27017,192.0.2.3:27017,192.0.2.4:27017,192.0.2.5:27017,192.0.2.6:27017,192.0.2.7:27017,192.0.2.8:27017/?replicaSet=rs0&serverSelectionTimeoutMS=1500&connectTimeoutMS=500&heartbeatFrequencyMS=100000 (hosts are intentionally unreachable)
59 [main] INFO org.mongodb.driver.cluster - Adding discovered server 192.0.2.1:27017 to client view of cluster
80 [main] INFO org.mongodb.driver.cluster - Adding discovered server 192.0.2.2:27017 to client view of cluster
80 [main] INFO org.mongodb.driver.cluster - Adding discovered server 192.0.2.3:27017 to client view of cluster
80 [main] INFO org.mongodb.driver.cluster - Adding discovered server 192.0.2.4:27017 to client view of cluster
80 [main] INFO org.mongodb.driver.cluster - Adding discovered server 192.0.2.5:27017 to client view of cluster
80 [main] INFO org.mongodb.driver.cluster - Adding discovered server 192.0.2.6:27017 to client view of cluster
81 [main] INFO org.mongodb.driver.cluster - Adding discovered server 192.0.2.7:27017 to client view of cluster
81 [main] INFO org.mongodb.driver.cluster - Adding discovered server 192.0.2.8:27017 to client view of cluster
101 [cluster-6a4c981ac59fd96c39728df3-192.0.2.1:27017] ERROR org.mongodb.driver.cluster - Thread[#56,cluster-6a4c981ac59fd96c39728df3-192.0.2.1:27017,5,main] for ServerId{clusterId=ClusterId{value='6a4c981ac59fd96c39728df3', description='null'}, address=192.0.2.1:27017} stopped working. You may want to recreate the MongoClient
java.lang.NoClassDefFoundError: com/mongodb/internal/connection/InternalStreamConnection
at com.mongodb.internal.connection.InternalStreamConnectionFactory.create(InternalStreamConnectionFactory.java:77)
at com.mongodb.internal.connection.InternalConnectionFactory.create(InternalConnectionFactory.java:27)
at com.mongodb.internal.connection.DefaultServerMonitor$ServerMonitor.setupNewConnectionAndGetInitialDescription(DefaultServerMonitor.java:278)
at com.mongodb.internal.connection.DefaultServerMonitor$ServerMonitor.lookupServerDescription(DefaultServerMonitor.java:253)
at com.mongodb.internal.connection.DefaultServerMonitor$ServerMonitor.run(DefaultServerMonitor.java:203)
Caused by: java.lang.ClassNotFoundException: com.mongodb.internal.connection.InternalStreamConnection
at java.base/java.net.URLClassLoader.findClass(URLClassLoader.java:369)
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:557)
at org.springframework.boot.loader.net.protocol.jar.JarUrlClassLoader.loadClass(JarUrlClassLoader.java:107)
at org.springframework.boot.loader.launch.LaunchedClassLoader.loadClass(LaunchedClassLoader.java:91)
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:490)
... 5 more
Caused by: java.util.zip.ZipException: ZipFile closed
at org.springframework.boot.loader.jar.NestedJarFile$JarEntryInputStream.ensureOpen(NestedJarFile.java:761)
at org.springframework.boot.loader.jar.NestedJarFile$JarEntryInputStream.read(NestedJarFile.java:722)
at java.base/java.util.zip.InflaterInputStream.fill(InflaterInputStream.java:308)
at org.springframework.boot.loader.jar.ZipInflaterInputStream.fill(ZipInflaterInputStream.java:67)
at java.base/java.util.zip.InflaterInputStream.read(InflaterInputStream.java:208)
at org.springframework.boot.loader.jar.ZipInflaterInputStream.read(ZipInflaterInputStream.java:57)
at org.springframework.boot.loader.net.protocol.jar.LazyDelegatingInputStream.read(LazyDelegatingInputStream.java:43)
at java.base/jdk.internal.loader.Resource.getBytes(Resource.java:106)
at java.base/java.net.URLClassLoader.defineClass(URLClassLoader.java:449)
at java.base/java.net.URLClassLoader.findClass(URLClassLoader.java:367)
... 9 more
101 [cluster-6a4c981ac59fd96c39728df3-192.0.2.3:27017] ERROR org.mongodb.driver.cluster - Thread[#58,cluster-6a4c981ac59fd96c39728df3-192.0.2.3:27017,5,main] for ServerId{clusterId=ClusterId{value='6a4c981ac59fd96c39728df3', description='null'}, address=192.0.2.3:27017} stopped working. You may want to recreate the MongoClient
java.lang.NoClassDefFoundError: com/mongodb/internal/connection/InternalStreamConnection
at com.mongodb.internal.connection.InternalStreamConnectionFactory.create(InternalStreamConnectionFactory.java:77)
at com.mongodb.internal.connection.InternalConnectionFactory.create(InternalConnectionFactory.java:27)
at com.mongodb.internal.connection.DefaultServerMonitor$ServerMonitor.setupNewConnectionAndGetInitialDescription(DefaultServerMonitor.java:278)
at com.mongodb.internal.connection.DefaultServerMonitor$ServerMonitor.lookupServerDescription(DefaultServerMonitor.java:253)
at com.mongodb.internal.connection.DefaultServerMonitor$ServerMonitor.run(DefaultServerMonitor.java:203)
Caused by: java.lang.ClassNotFoundException: com.mongodb.internal.connection.InternalStreamConnection
... 5 more
110 [main] INFO org.mongodb.driver.client - MongoClient with metadata {"driver": {"name": "mongo-java-driver|sync", "version": "5.8.0"}, "os": {"type": "Darwin", "name": "Mac OS X", "architecture": "aarch64", "version": "26.5.2"}, "platform": "Java/Amazon.com Inc./25.0.2+10-LTS"} created with settings MongoClientSettings{readPreference=primary, writeConcern=WriteConcern{w=null, wTimeout=null ms, journal=null}, retryWrites=true, retryReads=true, readConcern=ReadConcern{level=null}, credential=null, transportSettings=null, commandListeners=[], codecRegistry=ProvidersCodecRegistry{codecProviders=[ValueCodecProvider{}, BsonValueCodecProvider{}, DBRefCodecProvider{}, DBObjectCodecProvider{}, DocumentCodecProvider{}, CollectionCodecProvider{}, IterableCodecProvider{}, MapCodecProvider{}, GeoJsonCodecProvider{}, GridFSFileCodecProvider{}, Jsr310CodecProvider{}, JsonObjectCodecProvider{}, BsonCodecProvider{}, com.mongodb.client.model.mql.ExpressionCodecProvider@3234f74e, com.mongodb.Jep395RecordCodecProvider@7bc10d84, com.mongodb.KotlinCodecProvider@275fe372, EnumCodecProvider{}]}, loggerSettings=LoggerSettings{maxDocumentLength=1000}, clusterSettings={hosts=[192.0.2.1:27017, 192.0.2.2:27017, 192.0.2.3:27017, 192.0.2.4:27017, 192.0.2.5:27017, 192.0.2.6:27017, 192.0.2.7:27017, 192.0.2.8:27017], srvServiceName=mongodb, mode=MULTIPLE, requiredClusterType=REPLICA_SET, requiredReplicaSetName='rs0', serverSelector='null', clusterListeners='[]', serverSelectionTimeout='1500 ms', localThreshold='15 ms'}, socketSettings=SocketSettings{connectTimeoutMS=500, readTimeoutMS=0, receiveBufferSize=0, proxySettings=ProxySettings{host=null, port=null, username=null, password=null}}, heartbeatSocketSettings=SocketSettings{connectTimeoutMS=500, readTimeoutMS=500, receiveBufferSize=0, proxySettings=ProxySettings{host=null, port=null, username=null, password=null}}, connectionPoolSettings=ConnectionPoolSettings{maxSize=100, minSize=0, maxWaitTimeMS=120000, maxConnectionLifeTimeMS=0, maxConnectionIdleTimeMS=0, maintenanceInitialDelayMS=0, maintenanceFrequencyMS=60000, connectionPoolListeners=[], maxConnecting=2}, serverSettings=ServerSettings{heartbeatFrequencyMS=100000, minHeartbeatFrequencyMS=500, serverMonitoringMode=AUTO, serverListeners='[]', serverMonitorListeners='[]'}, sslSettings=SslSettings{enabled=false, invalidHostNameAllowed=false, context=null}, applicationName='null', compressorList=[], uuidRepresentation=UNSPECIFIED, serverApi=null, autoEncryptionSettings=null, dnsClient=null, inetAddressResolver=null, contextProvider=null, timeoutMS=null}
Exception in thread "cluster-6a4c981ac59fd96c39728df3-192.0.2.1:27017" java.lang.NoClassDefFoundError: com/mongodb/internal/connection/InternalStreamConnection
at com.mongodb.internal.connection.InternalStreamConnectionFactory.create(InternalStreamConnectionFactory.java:77)
at com.mongodb.internal.connection.InternalConnectionFactory.create(InternalConnectionFactory.java:27)
at com.mongodb.internal.connection.DefaultServerMonitor$ServerMonitor.setupNewConnectionAndGetInitialDescription(DefaultServerMonitor.java:278)
at com.mongodb.internal.connection.DefaultServerMonitor$ServerMonitor.lookupServerDescription(DefaultServerMonitor.java:253)
at com.mongodb.internal.connection.DefaultServerMonitor$ServerMonitor.run(DefaultServerMonitor.java:203)
Caused by: java.lang.ClassNotFoundException: com.mongodb.internal.connection.InternalStreamConnection
at java.base/java.net.URLClassLoader.findClass(URLClassLoader.java:369)
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:557)
at org.springframework.boot.loader.net.protocol.jar.JarUrlClassLoader.loadClass(JarUrlClassLoader.java:107)
at org.springframework.boot.loader.launch.LaunchedClassLoader.loadClass(LaunchedClassLoader.java:91)
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:490)
... 5 more
Caused by: java.util.zip.ZipException: ZipFile closed
at org.springframework.boot.loader.jar.NestedJarFile$JarEntryInputStream.ensureOpen(NestedJarFile.java:761)
at org.springframework.boot.loader.jar.NestedJarFile$JarEntryInputStream.read(NestedJarFile.java:722)
at java.base/java.util.zip.InflaterInputStream.fill(InflaterInputStream.java:308)
at org.springframework.boot.loader.jar.ZipInflaterInputStream.fill(ZipInflaterInputStream.java:67)
at java.base/java.util.zip.InflaterInputStream.read(InflaterInputStream.java:208)
at org.springframework.boot.loader.jar.ZipInflaterInputStream.read(ZipInflaterInputStream.java:57)
at org.springframework.boot.loader.net.protocol.jar.LazyDelegatingInputStream.read(LazyDelegatingInputStream.java:43)
at java.base/jdk.internal.loader.Resource.getBytes(Resource.java:106)
at java.base/java.net.URLClassLoader.defineClass(URLClassLoader.java:449)
at java.base/java.net.URLClassLoader.findClass(URLClassLoader.java:367)
... 9 more
Exception in thread "cluster-6a4c981ac59fd96c39728df3-192.0.2.3:27017" java.lang.NoClassDefFoundError: com/mongodb/internal/connection/InternalStreamConnection
at com.mongodb.internal.connection.InternalStreamConnectionFactory.create(InternalStreamConnectionFactory.java:77)
at com.mongodb.internal.connection.InternalConnectionFactory.create(InternalConnectionFactory.java:27)
at com.mongodb.internal.connection.DefaultServerMonitor$ServerMonitor.setupNewConnectionAndGetInitialDescription(DefaultServerMonitor.java:278)
at com.mongodb.internal.connection.DefaultServerMonitor$ServerMonitor.lookupServerDescription(DefaultServerMonitor.java:253)
at com.mongodb.internal.connection.DefaultServerMonitor$ServerMonitor.run(DefaultServerMonitor.java:203)
Caused by: java.lang.ClassNotFoundException: com.mongodb.internal.connection.InternalStreamConnection
... 5 more
118 [cluster-6a4c981ac59fd96c39728df3-192.0.2.2:27017] ERROR org.mongodb.driver.cluster - Thread[#57,cluster-6a4c981ac59fd96c39728df3-192.0.2.2:27017,5,main] for ServerId{clusterId=ClusterId{value='6a4c981ac59fd96c39728df3', description='null'}, address=192.0.2.2:27017} stopped working. You may want to recreate the MongoClient
java.lang.NoClassDefFoundError: com/mongodb/internal/connection/InternalStreamConnection
at com.mongodb.internal.connection.InternalStreamConnectionFactory.create(InternalStreamConnectionFactory.java:77)
at com.mongodb.internal.connection.InternalConnectionFactory.create(InternalConnectionFactory.java:27)
at com.mongodb.internal.connection.DefaultServerMonitor$ServerMonitor.setupNewConnectionAndGetInitialDescription(DefaultServerMonitor.java:278)
at com.mongodb.internal.connection.DefaultServerMonitor$ServerMonitor.lookupServerDescription(DefaultServerMonitor.java:253)
at com.mongodb.internal.connection.DefaultServerMonitor$ServerMonitor.run(DefaultServerMonitor.java:203)
Caused by: java.lang.ClassNotFoundException: com.mongodb.internal.connection.InternalStreamConnection
... 5 more
Exception in thread "cluster-6a4c981ac59fd96c39728df3-192.0.2.2:27017" java.lang.NoClassDefFoundError: com/mongodb/internal/connection/InternalStreamConnection
at com.mongodb.internal.connection.InternalStreamConnectionFactory.create(InternalStreamConnectionFactory.java:77)
at com.mongodb.internal.connection.InternalConnectionFactory.create(InternalConnectionFactory.java:27)
at com.mongodb.internal.connection.DefaultServerMonitor$ServerMonitor.setupNewConnectionAndGetInitialDescription(DefaultServerMonitor.java:278)
at com.mongodb.internal.connection.DefaultServerMonitor$ServerMonitor.lookupServerDescription(DefaultServerMonitor.java:253)
at com.mongodb.internal.connection.DefaultServerMonitor$ServerMonitor.run(DefaultServerMonitor.java:203)
Caused by: java.lang.ClassNotFoundException: com.mongodb.internal.connection.InternalStreamConnection
... 5 more
128 [cluster-6a4c981ac59fd96c39728df3-192.0.2.4:27017] ERROR org.mongodb.driver.cluster - Thread[#59,cluster-6a4c981ac59fd96c39728df3-192.0.2.4:27017,5,main] for ServerId{clusterId=ClusterId{value='6a4c981ac59fd96c39728df3', description='null'}, address=192.0.2.4:27017} stopped working. You may want to recreate the MongoClient
java.lang.NoClassDefFoundError: com/mongodb/internal/connection/InternalStreamConnection
at com.mongodb.internal.connection.InternalStreamConnectionFactory.create(InternalStreamConnectionFactory.java:77)
at com.mongodb.internal.connection.InternalConnectionFactory.create(InternalConnectionFactory.java:27)
at com.mongodb.internal.connection.DefaultServerMonitor$ServerMonitor.setupNewConnectionAndGetInitialDescription(DefaultServerMonitor.java:278)
at com.mongodb.internal.connection.DefaultServerMonitor$ServerMonitor.lookupServerDescription(DefaultServerMonitor.java:253)
at com.mongodb.internal.connection.DefaultServerMonitor$ServerMonitor.run(DefaultServerMonitor.java:203)
Caused by: java.lang.ClassNotFoundException: com.mongodb.internal.connection.InternalStreamConnection
... 5 more
Exception in thread "cluster-6a4c981ac59fd96c39728df3-192.0.2.4:27017" java.lang.NoClassDefFoundError: com/mongodb/internal/connection/InternalStreamConnection
at com.mongodb.internal.connection.InternalStreamConnectionFactory.create(InternalStreamConnectionFactory.java:77)
at com.mongodb.internal.connection.InternalConnectionFactory.create(InternalConnectionFactory.java:27)
at com.mongodb.internal.connection.DefaultServerMonitor$ServerMonitor.setupNewConnectionAndGetInitialDescription(DefaultServerMonitor.java:278)
at com.mongodb.internal.connection.DefaultServerMonitor$ServerMonitor.lookupServerDescription(DefaultServerMonitor.java:253)
at com.mongodb.internal.connection.DefaultServerMonitor$ServerMonitor.run(DefaultServerMonitor.java:203)
Caused by: java.lang.ClassNotFoundException: com.mongodb.internal.connection.InternalStreamConnection
... 5 more
RACE_REPRODUCED: 'NoClassDefFoundError' observed in a cluster-monitor thread
DIAGNOSTIC_REPORT: /var/folders/9r/mrxrn12567v24xty0cwy8y000000gp/T/tmp.6shAETnkLX/diagnostics/hit-20260707-080930-316-pid10988
135 [cluster-6a4c981ac59fd96c39728df3-192.0.2.5:27017] ERROR org.mongodb.driver.cluster - Thread[#60,cluster-6a4c981ac59fd96c39728df3-192.0.2.5:27017,5,main] for ServerId{clusterId=ClusterId{value='6a4c981ac59fd96c39728df3', description='null'}, address=192.0.2.5:27017} stopped working. You may want to recreate the MongoClient
java.lang.NoClassDefFoundError: com/mongodb/internal/connection/InternalStreamConnection
at com.mongodb.internal.connection.InternalStreamConnectionFactory.create(InternalStreamConnectionFactory.java:77)
at com.mongodb.internal.connection.InternalConnectionFactory.create(InternalConnectionFactory.java:27)
at com.mongodb.internal.connection.DefaultServerMonitor$ServerMonitor.setupNewConnectionAndGetInitialDescription(DefaultServerMonitor.java:278)
at com.mongodb.internal.connection.DefaultServerMonitor$ServerMonitor.lookupServerDescription(DefaultServerMonitor.java:253)
at com.mongodb.internal.connection.DefaultServerMonitor$ServerMonitor.run(DefaultServerMonitor.java:203)
Caused by: java.lang.ClassNotFoundException: com.mongodb.internal.connection.InternalStreamConnection
... 5 more
Exception in thread "cluster-6a4c981ac59fd96c39728df3-192.0.2.5:27017" java.lang.NoClassDefFoundError: com/mongodb/internal/connection/InternalStreamConnection
at com.mongodb.internal.connection.InternalStreamConnectionFactory.create(InternalStreamConnectionFactory.java:77)
at com.mongodb.internal.connection.InternalConnectionFactory.create(InternalConnectionFactory.java:27)
at com.mongodb.internal.connection.DefaultServerMonitor$ServerMonitor.setupNewConnectionAndGetInitialDescription(DefaultServerMonitor.java:278)
at com.mongodb.internal.connection.DefaultServerMonitor$ServerMonitor.lookupServerDescription(DefaultServerMonitor.java:253)
at com.mongodb.internal.connection.DefaultServerMonitor$ServerMonitor.run(DefaultServerMonitor.java:203)
Caused by: java.lang.ClassNotFoundException: com.mongodb.internal.connection.InternalStreamConnection
... 5 more
142 [cluster-6a4c981ac59fd96c39728df3-192.0.2.6:27017] ERROR org.mongodb.driver.cluster - Thread[#61,cluster-6a4c981ac59fd96c39728df3-192.0.2.6:27017,5,main] for ServerId{clusterId=ClusterId{value='6a4c981ac59fd96c39728df3', description='null'}, address=192.0.2.6:27017} stopped working. You may want to recreate the MongoClient
java.lang.NoClassDefFoundError: com/mongodb/internal/connection/InternalStreamConnection
at com.mongodb.internal.connection.InternalStreamConnectionFactory.create(InternalStreamConnectionFactory.java:77)
at com.mongodb.internal.connection.InternalConnectionFactory.create(InternalConnectionFactory.java:27)
at com.mongodb.internal.connection.DefaultServerMonitor$ServerMonitor.setupNewConnectionAndGetInitialDescription(DefaultServerMonitor.java:278)
at com.mongodb.internal.connection.DefaultServerMonitor$ServerMonitor.lookupServerDescription(DefaultServerMonitor.java:253)
at com.mongodb.internal.connection.DefaultServerMonitor$ServerMonitor.run(DefaultServerMonitor.java:203)
Caused by: java.lang.ClassNotFoundException: com.mongodb.internal.connection.InternalStreamConnection
... 5 more
Exception in thread "cluster-6a4c981ac59fd96c39728df3-192.0.2.6:27017" java.lang.NoClassDefFoundError: com/mongodb/internal/connection/InternalStreamConnection
at com.mongodb.internal.connection.InternalStreamConnectionFactory.create(InternalStreamConnectionFactory.java:77)
at com.mongodb.internal.connection.InternalConnectionFactory.create(InternalConnectionFactory.java:27)
at com.mongodb.internal.connection.DefaultServerMonitor$ServerMonitor.setupNewConnectionAndGetInitialDescription(DefaultServerMonitor.java:278)
at com.mongodb.internal.connection.DefaultServerMonitor$ServerMonitor.lookupServerDescription(DefaultServerMonitor.java:253)
at com.mongodb.internal.connection.DefaultServerMonitor$ServerMonitor.run(DefaultServerMonitor.java:203)
Caused by: java.lang.ClassNotFoundException: com.mongodb.internal.connection.InternalStreamConnection
... 5 more
148 [cluster-6a4c981ac59fd96c39728df3-192.0.2.7:27017] ERROR org.mongodb.driver.cluster - Thread[#62,cluster-6a4c981ac59fd96c39728df3-192.0.2.7:27017,5,main] for ServerId{clusterId=ClusterId{value='6a4c981ac59fd96c39728df3', description='null'}, address=192.0.2.7:27017} stopped working. You may want to recreate the MongoClient
java.lang.NoClassDefFoundError: com/mongodb/internal/connection/InternalStreamConnection
at com.mongodb.internal.connection.InternalStreamConnectionFactory.create(InternalStreamConnectionFactory.java:77)
at com.mongodb.internal.connection.InternalConnectionFactory.create(InternalConnectionFactory.java:27)
at com.mongodb.internal.connection.DefaultServerMonitor$ServerMonitor.setupNewConnectionAndGetInitialDescription(DefaultServerMonitor.java:278)
at com.mongodb.internal.connection.DefaultServerMonitor$ServerMonitor.lookupServerDescription(DefaultServerMonitor.java:253)
at com.mongodb.internal.connection.DefaultServerMonitor$ServerMonitor.run(DefaultServerMonitor.java:203)
Caused by: java.lang.ClassNotFoundException: com.mongodb.internal.connection.InternalStreamConnection
... 5 more
Exception in thread "cluster-6a4c981ac59fd96c39728df3-192.0.2.7:27017" java.lang.NoClassDefFoundError: com/mongodb/internal/connection/InternalStreamConnection
at com.mongodb.internal.connection.InternalStreamConnectionFactory.create(InternalStreamConnectionFactory.java:77)
at com.mongodb.internal.connection.InternalConnectionFactory.create(InternalConnectionFactory.java:27)
at com.mongodb.internal.connection.DefaultServerMonitor$ServerMonitor.setupNewConnectionAndGetInitialDescription(DefaultServerMonitor.java:278)
at com.mongodb.internal.connection.DefaultServerMonitor$ServerMonitor.lookupServerDescription(DefaultServerMonitor.java:253)
at com.mongodb.internal.connection.DefaultServerMonitor$ServerMonitor.run(DefaultServerMonitor.java:203)
Caused by: java.lang.ClassNotFoundException: com.mongodb.internal.connection.InternalStreamConnection
... 5 more
155 [cluster-6a4c981ac59fd96c39728df3-192.0.2.8:27017] ERROR org.mongodb.driver.cluster - Thread[#63,cluster-6a4c981ac59fd96c39728df3-192.0.2.8:27017,5,main] for ServerId{clusterId=ClusterId{value='6a4c981ac59fd96c39728df3', description='null'}, address=192.0.2.8:27017} stopped working. You may want to recreate the MongoClient
java.lang.NoClassDefFoundError: com/mongodb/internal/connection/InternalStreamConnection
at com.mongodb.internal.connection.InternalStreamConnectionFactory.create(InternalStreamConnectionFactory.java:77)
at com.mongodb.internal.connection.InternalConnectionFactory.create(InternalConnectionFactory.java:27)
at com.mongodb.internal.connection.DefaultServerMonitor$ServerMonitor.setupNewConnectionAndGetInitialDescription(DefaultServerMonitor.java:278)
at com.mongodb.internal.connection.DefaultServerMonitor$ServerMonitor.lookupServerDescription(DefaultServerMonitor.java:253)
at com.mongodb.internal.connection.DefaultServerMonitor$ServerMonitor.run(DefaultServerMonitor.java:203)
Caused by: java.lang.ClassNotFoundException: com.mongodb.internal.connection.InternalStreamConnection
... 5 more
Exception in thread "cluster-6a4c981ac59fd96c39728df3-192.0.2.8:27017" java.lang.NoClassDefFoundError: com/mongodb/internal/connection/InternalStreamConnection
at com.mongodb.internal.connection.InternalStreamConnectionFactory.create(InternalStreamConnectionFactory.java:77)
at com.mongodb.internal.connection.InternalConnectionFactory.create(InternalConnectionFactory.java:27)
at com.mongodb.internal.connection.DefaultServerMonitor$ServerMonitor.setupNewConnectionAndGetInitialDescription(DefaultServerMonitor.java:278)
at com.mongodb.internal.connection.DefaultServerMonitor$ServerMonitor.lookupServerDescription(DefaultServerMonitor.java:253)
at com.mongodb.internal.connection.DefaultServerMonitor$ServerMonitor.run(DefaultServerMonitor.java:203)
Caused by: java.lang.ClassNotFoundException: com.mongodb.internal.connection.InternalStreamConnection
... 5 more
jvm.log
stderr.log
stdout-stderr.log
threaddump-at-failure.txt
Activity
arnabnandy7 commentedon Jul 18, 2026
I tried the supplied reproducer from https://github.com/janjanneck7777/springboot-loader-race-repro and was unable to reproduce the failure in the environments available to me.
Result
I ran 800 fresh JVM launches in total with the Elastic APM agent enabled and
hosts=16to increase contention:Neither arm produced
RACE_REPRODUCED,NoClassDefFoundError, norZipFile closed.Both runs were x86_64. I did not have an ARM/aarch64 environment available, so this does not cover the reporter's macOS/aarch64/JDK 25 combination.
Versions from the reproducer
requiresUnpack)Build
On Windows:
This produced:
Windows stress run
The test stopped on the first matching failure marker; otherwise it completed 400 attempts:
Result:
0 / 400.WSL2/Linux stress run
I reused the same built fat JAR and launched it using the Linux JVM, once per iteration:
Result:
0 / 400.This outcome is consistent with the issue being timing-, scheduler-, JVM-, or platform-sensitive; it does not invalidate the macOS/aarch64 reproduction reported above. A useful next comparison would be native macOS/aarch64 with JDK 25, followed by a cold/constrained native Linux environment rather than WSL2.
wilkinsona commentedon Jul 19, 2026
Thank you, @janjanneck7777. I've reproduced the problem on macOS:
We've got a lot of other, unfortunately higher priority, work on our plates at the moment, but I wanted to at least acknowledge that we can now reproduce the problem. Thank you.
The question that I think we really need to answer if what's closing the
NestedJarFileorJarEntryInputStreamon one thread such that another thread ends up trying to use a closed instance. I haven't been able to find that answer in the diagnostics, but I also haven't had a huge amount of time to look. Regardless, being able to reproduce the problem is a significant step forwards.amarcalfaria commentedon Aug 6, 2026
Possibly a sibling of this in the same subsystem, with a different symptom: instead of
ZipException: ZipFile closed, the application silently hangs forever.Environment: Spring Boot 4.1.0, OpenJDK 25.0.2+10-LTS, fat jar, embedded Tomcat with virtual threads, 4 vCPU.
Symptom: process stays alive and keeps completing TCP handshakes, but never completes another HTTP response. Nothing thrown, nothing logged, never recovers. Hits ~1.5-3% of otherwise identical fresh JVMs, always in the first seconds of traffic while classes are still loading for the first time.
Chain
Identical on five hosts:
The jar monitor holder is always a message-broker channel thread:
The request threads sit one level up at
NestedJarFile.hasEntry(NestedJarFile.java:251), waiting for the monitor that thread holds.The
FileAccesslock has no ownerkill -3cannot see unmounted virtual threads, so we assumed the owner was merely invisible. It is not. Ajcmd Thread.dump_to_file -format=jsondump shows 93 threads, 52 virtual, and the lock object appears exactly once in the whole file, as theblockedOnof the waiting platform thread. It is in nomonitorsOwnedarray on any thread. Confirmed on two hosts, three dumps each, five seconds apart. No "Found one Java-level deadlock" is printed.Ruled out:
close()never took the count to zero.fillBufferUsingRandomAccessFile/repairFileChannelframes, noClosedByInterruptException.parallelism = 4, size = 4, active = 4, running = 0, 43 queued. The head of the chain is a platform thread, so freeing carriers cannot release it. Raisingjdk.virtualThreadScheduler.parallelismchanges nothing.Repro condition
Only reproduces where the jar is cold in page cache:
fincoreshows ~42% resident on affected machines versus 100% where the jar stays warm, and it has never reproduced warm.FileAccess.readholds its lock acrossfillBufferand therefore across a realFileChannel.read, so a cold cache turns that critical section into disk I/O and widens the window. Cold cache alone is not the trigger though: affected and unaffected machines from the same image show the same residency (42.1 / 42.3 versus 43.2).Question
Separate issue, or same defect as the
ZipExceptionhere? Same subsystem, same JDK build family, both concurrency-dependent, but a different outcome. Happy to attach the full JSON thread dumps.wilkinsona commentedon Aug 17, 2026
@amarcalfaria unless you're using the Elastic APM agent, that's a different problem. Even if you are using it, the symptoms are so different, it's almost certainly a different problem. In terms of symptoms, #51379 sounds similar but the circumstances are still quite different. Please create a minimal reproducer and then open a new issue and we'll take things from there.
wilkinsona commentedon Aug 17, 2026
elastic/apm-agent-java#4541 identifies the root cause of the problem. Thank you, @aayushsrivastava.
The Elastic APM agent was using a
JarURLConnectionwith caching enabled, retrieving the cached and shared jar file and then closing it unconditionally. This has been fixed in elastic/apm-agent-java#4543. Anyone affected by this issue should update to a new release of the Elastic APM agent once available. In the meantime, disabling the agent is the only known workaround.SylvainJuge commentedon Sep 8, 2026
The elastic/apm-agent-java release 1.57.0 is now available with a fix to prevent this issue from happening.
Upgrade Reflections to 0.9.12 to avoid closing shared JarFiles (#7057)