MongoSocketReadException and MongoSocketOpenException
I am unable to ascertian the reason for these errors. They both occur as a result of datastore.ensureIndexes() in the following, at the very initialisation of this plugin:
private MongoClient mc;
private Morphia morphia;
private Datastore datastore;
public static myDAO dao;
public void DatabaseHandler() {
mc = new MongoClient();
morphia = new Morphia();
morphia.map(storedData.class);
datastore = morphia.createDatastore(mc, "datastore");
datastore.ensureIndexes();
dao = new myDAO(storedData.class, datastore);
System.out.println("DatabaseHandler called");
}
When this is called, at the very start of the initialisation of the plugin essentially, one of these errors appears. It was once MongoSocketOpenException and has recently changed to MongoSocketReadException. As you can tell, I am accessing a database on the localhost with no credentials. I receive this error at runtime and I am unaware of how to fix it as I have no networking experience really. Please help:
[10:59:12 INFO]: Cluster created with settings {hosts=[127.0.0.1:27017], mode=SINGLE, requiredClusterType=UNKNOWN, serverSelectionTimeout='30000 ms', maxWaitQueueSize=500}
[10:59:12 INFO]: LoggerImplFactory set to org.mongodb.morphia.logging.jdk.JDKLoggerFactory
[10:59:12 INFO]: No server chosen by WritableServerSelector from cluster description ClusterDescription{type=UNKNOWN, connectionMode=SINGLE, serverDescriptions=[ServerDescription{address=127.0.0.1:27017, type=UNKNOWN, state=CONNECTING}]}. Waiting for 30000 ms before timing out
[10:59:13 INFO]: Exception in monitor thread while connecting to server 127.0.0.1:27017
com.mongodb.MongoSocketOpenException: Exception opening socket
at com.mongodb.connection.SocketStream.open(SocketStream.java:63) ~[Plugin-0.0.1-SNAPSHOT-shaded.jar:?]
at com.mongodb.connection.InternalStreamConnection.open(InternalStreamConnection.java:115) ~[Plugin-0.0.1-SNAPSHOT-shaded.jar:?]
at com.mongodb.connection.DefaultServerMonitor$ServerMonitorRunnable.run(DefaultServerMonitor.java:113) [Plugin-0.0.1-SNAPSHOT-shaded.jar:?]
at java.lang.Thread.run(Unknown Source) [?:1.8.0_151]
Caused by: java.net.ConnectException: Connection refused: connect
at java.net.DualStackPlainSocketImpl.waitForConnect(Native Method) ~[?:1.8.0_151]
at java.net.DualStackPlainSocketImpl.socketConnect(Unknown Source) ~[?:1.8.0_151]
at java.net.AbstractPlainSocketImpl.doConnect(Unknown Source) ~[?:1.8.0_151]
at java.net.AbstractPlainSocketImpl.connectToAddress(Unknown Source) ~[?:1.8.0_151]
at java.net.AbstractPlainSocketImpl.connect(Unknown Source) ~[?:1.8.0_151]
at java.net.PlainSocketImpl.connect(Unknown Source) ~[?:1.8.0_151]
at java.net.SocksSocketImpl.connect(Unknown Source) ~[?:1.8.0_151]
at java.net.Socket.connect(Unknown Source) ~[?:1.8.0_151]
at com.mongodb.connection.SocketStreamHelper.initialize(SocketStreamHelper.java:57) ~[?:?]
at com.mongodb.connection.SocketStream.open(SocketStream.java:58) ~[?:?]
com.mongodb.MongoTimeoutException: Timed out after 30000 ms while waiting for a server that matches WritableServerSelector. Client view of cluster state is {type=UNKNOWN, servers=[{address=127.0.0.1:27017, type=UNKNOWN, state=CONNECTING, exception={com.mongodb.MongoSocketOpenException: Exception opening socket}, caused by {java.net.ConnectException: Connection refused: connect}}]`
AND this is the MongoSocketReadException version
`[21:52:48 INFO]: Cluster created with settings {hosts=[127.0.0.1:27017], mode=SINGLE, requiredClusterType=UNKNOWN, serverSelectionTimeout='30000 ms', maxWaitQueueSize=500}
[21:52:48 INFO]: LoggerImplFactory set to org.mongodb.morphia.logging.jdk.JDKLoggerFactory
[21:52:48 INFO]: Exception in monitor thread while connecting to server 127.0.0.1:27017
com.mongodb.MongoSocketReadException: Prematurely reached end of stream
at com.mongodb.connection.SocketStream.read(SocketStream.java:88) ~[MassStorage-0.0.1-SNAPSHOT-shaded.jar:?]
at com.mongodb.connection.InternalStreamConnection.receiveResponseBuffers(InternalStreamConnection.java:494) ~[MassStorage-0.0.1-SNAPSHOT-shaded.jar:?]
at com.mongodb.connection.InternalStreamConnection.receiveMessage(InternalStreamConnection.java:224) ~[MassStorage-0.0.1-SNAPSHOT-shaded.jar:?]
at com.mongodb.connection.CommandHelper.receiveReply(CommandHelper.java:134) ~[MassStorage-0.0.1-SNAPSHOT-shaded.jar:?]
at com.mongodb.connection.CommandHelper.receiveCommandResult(CommandHelper.java:121) ~[MassStorage-0.0.1-SNAPSHOT-shaded.jar:?]
at com.mongodb.connection.CommandHelper.executeCommand(CommandHelper.java:32) ~[MassStorage-0.0.1-SNAPSHOT-shaded.jar:?]
at com.mongodb.connection.InternalStreamConnectionInitializer.initializeConnectionDescription(InternalStreamConnectionInitializer.java:85) ~[MassStorage-0.0.1-SNAPSHOT-shaded.jar:?]
at com.mongodb.connection.InternalStreamConnectionInitializer.initialize(InternalStreamConnectionInitializer.java:45) ~[MassStorage-0.0.1-SNAPSHOT-shaded.jar:?]
at com.mongodb.connection.InternalStreamConnection.open(InternalStreamConnection.java:116) ~[MassStorage-0.0.1-SNAPSHOT-shaded.jar:?]
at com.mongodb.connection.DefaultServerMonitor$ServerMonitorRunnable.run(DefaultServerMonitor.java:113) [MassStorage-0.0.1-SNAPSHOT-shaded.jar:?]
at java.lang.Thread.run(Unknown Source) [?:1.8.0_151]
[21:52:49 INFO]: No server chosen by WritableServerSelector from cluster description ClusterDescription{type=UNKNOWN, connectionMode=SINGLE, serverDescriptions=[ServerDescription{address=127.0.0.1:27017, type=UNKNOWN, state=CONNECTING, exception={com.mongodb.MongoSocketReadException: Prematurely reached end of stream}}]}. Waiting for 30000 ms before timing out
[21:53:19 WARN]: [MassStorage] Plugin MassStorage v0.1 generated an exception while executing task 34
com.mongodb.MongoTimeoutException: Timed out after 30000 ms while waiting for a server that matches WritableServerSelector. Client view of cluster state is {type=UNKNOWN, servers=[{address=127.0.0.1:27017, type=UNKNOWN, state=CONNECTING, exception={com.mongodb.MongoSocketReadException: Prematurely reached end of stream}}]
Is your mongodb instance running on the localhost at the default port?
Hmmm, I'm new, so I didn't know I had to do that. So, I downloaded and installed mongodb. Tried to run mongod.exe, ran at the default port, and got this error: Failed to set up listener: SocketException: An attempt was made to access a socket in a way forbidden by its access permissions. How do I change the access permissions?
mondgod.exe gave that error or your java app? i've never seen that message before. if it's mongod.exe giving that error, i'd ask on the mongodb mailing lists.
The error in the previous message was thrown directly after running mongod.exe
I'm sorry I lost track of this but it does indeed look like an error running the server and not Morphia itself.