Registry error: MongoDB exception: com.mongodb.MongoSocketOpenException: Exception opening socket
search cancel

Registry error: MongoDB exception: com.mongodb.MongoSocketOpenException: Exception opening socket

book

Article ID: 277833

calendar_today

Updated On:

Products

Service Virtualization

Issue/Introduction

Getting this exception on MongoDB Service in the Registry log:

2023-11-29T03:53:20,049Z (22:53) [Thread-17] INFO  org.mongodb.driver.cluster     - Cluster created with settings {hosts=[localhost:27017], mode=SINGLE, requiredClusterType=UNKNOWN, serverSelectionTimeout='30000 ms', maxWaitQueueSize=500}
2023-11-29T03:53:20,051Z (22:53) [cluster-ClusterId{value='<cluster-ClusterId>', description='null'}-localhost:27017] INFO  org.mongodb.driver.cluster     - Exception in monitor thread while connecting to server localhost:27017
com.mongodb.MongoSocketOpenException: Exception opening socket
    at com.mongodb.internal.connection.SocketStream.open(SocketStream.java:70) ~[mongo-java-driver-3.12.14.jar:?]
    at com.mongodb.internal.connection.InternalStreamConnection.open(InternalStreamConnection.java:128) ~[mongo-java-driver-3.12.14.jar:?]
    at com.mongodb.internal.connection.DefaultServerMonitor$ServerMonitorRunnable.run(DefaultServerMonitor.java:117) [mongo-java-driver-3.12.14.jar:?]
    at java.lang.Thread.run(Thread.java:750) [?:1.8.0_352]
Caused by: java.net.ConnectException: Connection refused (Connection refused)
    at java.net.PlainSocketImpl.socketConnect(Native Method) ~[?:1.8.0_352]
    at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:350) ~[?:1.8.0_352]
    at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:206) ~[?:1.8.0_352]
    at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:188) ~[?:1.8.0_352]
    at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392) ~[?:1.8.0_352]
    at java.net.Socket.connect(Socket.java:607) ~[?:1.8.0_352]
    at com.mongodb.internal.connection.SocketStreamHelper.initialize(SocketStreamHelper.java:64) ~[mongo-java-driver-3.12.14.jar:?]
    at com.mongodb.internal.connection.SocketStream.initializeSocket(SocketStream.java:79) ~[mongo-java-driver-3.12.14.jar:?]
    at com.mongodb.internal.connection.SocketStream.open(SocketStream.java:65) ~[mongo-java-driver-3.12.14.jar:?]
    ... 3 more

 

Nothing is down, just want to know what this exception is.

Environment

DevTest 10.7.2 SP3

Cause

N/A

Resolution

When the MongoDB driver is included in the classpath of a Spring Boot application, Spring Boot will automatically try to connect to a MongoDB server. This assumes that the server is accessible locally at the default host (localhost) and port (27017). If the MongoDB server is not running or not available at the specified location, this attempt results in an error.

To enable auto-configurations for databases in a Spring Boot application, including the relevant database driver dependencies is essential. Specifically, for MongoDB, including the mongo-java-driver is sufficient, and Spring Boot will handle most configurations automatically. For other databases, we must include the corresponding driver dependencies and configure connection properties as well. If we wish to exclude certain auto-configurations, we can use the spring.autoconfigure.exclude property, specifying the fully qualified names of the classes we want to exclude.

For example, to exclude MongoDB auto-configuration, we can set spring.autoconfigure.exclude=org.springframework.boot.autoconfigure.mongo.MongoAutoConfiguration.

To disable MongoDB auto configuration please follow below steps:

1. Stop Registry Service
2. Delete all Registry log files.
3. Add below property in RegistryService.vmoptions
-Dspring.autoconfigure.exclude=org.springframework.boot.autoconfigure.mongo.MongoAutoConfiguration
4. Start Registry service.

Will not see the exception messages in the log file.