Discussion:
MongoDB: java.lang.IllegalStateException: state should
(too old to reply)
EG
2016-11-22 07:27:34 UTC
Permalink
I have an application that pulls data from one source and then upserts it
to MongoDB. Sometimes the pulling process takes a lot of time and when app
tries to push a row to MongoDB the following exception is raised probably
to the timeout issue:

com.mongodb.MongoSocketReadException: Prematurely reached end of stream
at com.mongodb.connection.SocketStream.read(SocketStream.java:88)
at
com.mongodb.connection.InternalStreamConnection.receiveResponseBuffers(InternalStreamConnection.java:492)
at
com.mongodb.connection.InternalStreamConnection.receiveMessage(InternalStreamConnection.java:222)
at
com.mongodb.connection.UsageTrackingInternalConnection.receiveMessage(UsageTrackingInternalConnection.java:105)
at
com.mongodb.connection.DefaultConnectionPool$PooledConnection.receiveMessage(DefaultConnectionPool.java:438)
at
com.mongodb.connection.WriteCommandProtocol.receiveMessage(WriteCommandProtocol.java:262)
at
com.mongodb.connection.WriteCommandProtocol.execute(WriteCommandProtocol.java:104)
at
com.mongodb.connection.UpdateCommandProtocol.execute(UpdateCommandProtocol.java:64)
at
com.mongodb.connection.UpdateCommandProtocol.execute(UpdateCommandProtocol.java:37)
at
com.mongodb.connection.DefaultServer$DefaultServerProtocolExecutor.execute(DefaultServer.java:168)
at
com.mongodb.connection.DefaultServerConnection.executeProtocol(DefaultServerConnection.java:289)
at
com.mongodb.connection.DefaultServerConnection.updateCommand(DefaultServerConnection.java:143)
at
com.mongodb.operation.MixedBulkWriteOperation$Run$3.executeWriteCommandProtocol(MixedBulkWriteOperation.java:481)
at
com.mongodb.operation.MixedBulkWriteOperation$Run$RunExecutor.execute(MixedBulkWriteOperation.java:647)
at
com.mongodb.operation.MixedBulkWriteOperation$Run.execute(MixedBulkWriteOperation.java:400)
at
com.mongodb.operation.MixedBulkWriteOperation$1.call(MixedBulkWriteOperation.java:180)
at
com.mongodb.operation.MixedBulkWriteOperation$1.call(MixedBulkWriteOperation.java:169)
at
com.mongodb.operation.OperationHelper.withConnectionSource(OperationHelper.java:232)
at
com.mongodb.operation.OperationHelper.withConnection(OperationHelper.java:223)
at
com.mongodb.operation.MixedBulkWriteOperation.execute(MixedBulkWriteOperation.java:169)
at
com.mongodb.operation.MixedBulkWriteOperation.execute(MixedBulkWriteOperation.java:75)
at com.mongodb.Mongo.execute(Mongo.java:827)
at com.mongodb.Mongo$2.execute(Mongo.java:810)
at
com.mongodb.MongoCollectionImpl.executeSingleWriteRequest(MongoCollectionImpl.java:515)
at com.mongodb.MongoCollectionImpl.update(MongoCollectionImpl.java:508)
at
com.mongodb.MongoCollectionImpl.updateOne(MongoCollectionImpl.java:355)
at
com.test.db.mongoDB.RetryingMongoCollection.updateOne(RetryingMongoCollection.java:909)

There is a wrapper for MongoCollection class that for each MongoException
and now for java.lang.IllegalStateException thrown

@Override
public UpdateResult updateOne(Bson filter, Bson update,
UpdateOptions updateOptions) {
UpdateResult retVal = null;
final ExceptionHelper ex = new ExceptionHelper(CAConstants.RETRIES,
ErrorType.ERROR, true);
boolean isDone = false;
while (!isDone) {
try {
retVal = proxied.updateOne(filter, update, updateOptions);
isDone = true;
} catch (final MongoException | IllegalStateException e) {
ex.logIfZero("Failed to launch MongoDB operation", e);
if (ex.lastTry()) {
isDone = true;
Log.error("Failed to launch MongoDB operation.", e);
} else {
Log.error("[MDB] Going to update mongo instance due to exception", e);
db = MongoDBFactory.getUpdatedMongoDBInstance();
setCollection();
}
}
}
return retVal;
}

tries to reload MongoClient:

if ( mongoClient != null ) {
try {
mongoClient.close();
} catch (Exception e) {
Log.error("Mongo client throws exception while closing connection", e);
}
...
mongoClient = new MongoClient(servers, Arrays.asList(credential),
new MongoClientOptions.Builder()
.requiredReplicaSetName(REPLICASET_NAME)
.connectTimeout(0)
.connectionsPerHost(CONNECTION_PER_HOST)
.cursorFinalizerEnabled(false)
.build());

db = mongoClient.getDatabase(database);


However, when the mongoClient is updated after
"com.mongodb.MongoSocketReadException: Prematurely reached end of stream"
it fails with:

java.lang.IllegalStateException: state should be: open
at com.mongodb.assertions.Assertions.isTrue(Assertions.java:70)
at com.mongodb.connection.BaseCluster.selectServer(BaseCluster.java:82)
at
com.mongodb.binding.ClusterBinding$ClusterBindingConnectionSource.<init>(ClusterBinding.java:75)
at
com.mongodb.binding.ClusterBinding$ClusterBindingConnectionSource.<init>(ClusterBinding.java:71)
at
com.mongodb.binding.ClusterBinding.getWriteConnectionSource(ClusterBinding.java:68)
at
com.mongodb.operation.OperationHelper.withConnection(OperationHelper.java:221)
at
com.mongodb.operation.MixedBulkWriteOperation.execute(MixedBulkWriteOperation.java:169)
at
com.mongodb.operation.MixedBulkWriteOperation.execute(MixedBulkWriteOperation.java:75)
at com.mongodb.Mongo.execute(Mongo.java:827)
at com.mongodb.Mongo$2.execute(Mongo.java:810)
at
com.mongodb.MongoCollectionImpl.executeSingleWriteRequest(MongoCollectionImpl.java:515)
at com.mongodb.MongoCollectionImpl.update(MongoCollectionImpl.java:508)
at
com.mongodb.MongoCollectionImpl.updateOne(MongoCollectionImpl.java:355)
at
com.test.db.mongoDB.RetryingMongoCollection.updateOne(RetryingMongoCollection.java:909)

and continues failing all the time...

I use mongoDB ver 3.0.6
Mongo java client 3.3.0

Please support.
--
You received this message because you are subscribed to the Google Groups "mongodb-user"
group.

For other MongoDB technical support options, see: https://docs.mongodb.com/manual/support/
---
You received this message because you are subscribed to the Google Groups "mongodb-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mongodb-user+***@googlegroups.com.
To post to this group, send email to mongodb-***@googlegroups.com.
Visit this group at https://groups.google.com/group/mongodb-user.
To view this discussion on the web visit https://groups.google.com/d/msgid/mongodb-user/9d591c09-7fd7-4177-a3b9-91f16966163b%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Ross Lawley
2016-11-22 11:34:54 UTC
Permalink
Hi EG,

Can I ask you to file a ticket in Jira: https://jira.mongodb.org/browse/JAVA
and we'll follow up the discussion there.

Many thanks,

Ross
Post by EG
I have an application that pulls data from one source and then upserts it
to MongoDB. Sometimes the pulling process takes a lot of time and when app
tries to push a row to MongoDB the following exception is raised probably
com.mongodb.MongoSocketReadException: Prematurely reached end of stream
at com.mongodb.connection.SocketStream.read(SocketStream.java:88)
at com.mongodb.connection.InternalStreamConnection.
receiveResponseBuffers(InternalStreamConnection.java:492)
at com.mongodb.connection.InternalStreamConnection.receiveMessage(
InternalStreamConnection.java:222)
at com.mongodb.connection.UsageTrackingInternalConnectio
n.receiveMessage(UsageTrackingInternalConnection.java:105)
at com.mongodb.connection.DefaultConnectionPool$PooledConnection.
receiveMessage(DefaultConnectionPool.java:438)
at com.mongodb.connection.WriteCommandProtocol.receiveMessage(
WriteCommandProtocol.java:262)
at com.mongodb.connection.WriteCommandProtocol.execute(
WriteCommandProtocol.java:104)
at com.mongodb.connection.UpdateCommandProtocol.execute(
UpdateCommandProtocol.java:64)
at com.mongodb.connection.UpdateCommandProtocol.execute(
UpdateCommandProtocol.java:37)
at com.mongodb.connection.DefaultServer$DefaultServerProtocolExecutor.
execute(DefaultServer.java:168)
at com.mongodb.connection.DefaultServerConnection.executeProtocol(
DefaultServerConnection.java:289)
at com.mongodb.connection.DefaultServerConnection.updateCommand(
DefaultServerConnection.java:143)
at com.mongodb.operation.MixedBulkWriteOperation$Run$3.
executeWriteCommandProtocol(MixedBulkWriteOperation.java:481)
at com.mongodb.operation.MixedBulkWriteOperation$Run$
RunExecutor.execute(MixedBulkWriteOperation.java:647)
at com.mongodb.operation.MixedBulkWriteOperation$Run.execute(
MixedBulkWriteOperation.java:400)
at com.mongodb.operation.MixedBulkWriteOperation$1.
call(MixedBulkWriteOperation.java:180)
at com.mongodb.operation.MixedBulkWriteOperation$1.
call(MixedBulkWriteOperation.java:169)
at com.mongodb.operation.OperationHelper.withConnectionSource(
OperationHelper.java:232)
at com.mongodb.operation.OperationHelper.withConnection(
OperationHelper.java:223)
at com.mongodb.operation.MixedBulkWriteOperation.execute(
MixedBulkWriteOperation.java:169)
at com.mongodb.operation.MixedBulkWriteOperation.execute(
MixedBulkWriteOperation.java:75)
at com.mongodb.Mongo.execute(Mongo.java:827)
at com.mongodb.Mongo$2.execute(Mongo.java:810)
at com.mongodb.MongoCollectionImpl.executeSingleWriteRequest(
MongoCollectionImpl.java:515)
at com.mongodb.MongoCollectionImpl.update(
MongoCollectionImpl.java:508)
at com.mongodb.MongoCollectionImpl.updateOne(
MongoCollectionImpl.java:355)
at com.test.db.mongoDB.RetryingMongoCollection.updateOne(
RetryingMongoCollection.java:909)
There is a wrapper for MongoCollection class that for each MongoException
and now for java.lang.IllegalStateException thrown
@Override
public UpdateResult updateOne(Bson filter, Bson update,
UpdateOptions updateOptions) {
UpdateResult retVal = null;
final ExceptionHelper ex = new ExceptionHelper(CAConstants.RETRIES,
ErrorType.ERROR, true);
boolean isDone = false;
while (!isDone) {
try {
retVal = proxied.updateOne(filter, update, updateOptions);
isDone = true;
} catch (final MongoException | IllegalStateException e) {
ex.logIfZero("Failed to launch MongoDB operation", e);
if (ex.lastTry()) {
isDone = true;
Log.error("Failed to launch MongoDB operation.", e);
} else {
Log.error("[MDB] Going to update mongo instance due to exception", e);
db = MongoDBFactory.getUpdatedMongoDBInstance();
setCollection();
}
}
}
return retVal;
}
if ( mongoClient != null ) {
try {
mongoClient.close();
} catch (Exception e) {
Log.error("Mongo client throws exception while closing connection", e);
}
...
mongoClient = new MongoClient(servers, Arrays.asList(credential),
new MongoClientOptions.Builder()
.requiredReplicaSetName(REPLICASET_NAME)
.connectTimeout(0)
.connectionsPerHost(CONNECTION_PER_HOST)
.cursorFinalizerEnabled(false)
.build());
db = mongoClient.getDatabase(database);
java.lang.IllegalStateException: state should be: open
at com.mongodb.assertions.Assertions.isTrue(Assertions.java:70)
at com.mongodb.connection.BaseCluster.selectServer(
BaseCluster.java:82)
at com.mongodb.binding.ClusterBinding$ClusterBindingConnectionSource
.<init>(ClusterBinding.java:75)
at com.mongodb.binding.ClusterBinding$ClusterBindingConnectionSource
.<init>(ClusterBinding.java:71)
at com.mongodb.binding.ClusterBinding.getWriteConnectionSource(
ClusterBinding.java:68)
at com.mongodb.operation.OperationHelper.withConnection(
OperationHelper.java:221)
at com.mongodb.operation.MixedBulkWriteOperation.execute(
MixedBulkWriteOperation.java:169)
at com.mongodb.operation.MixedBulkWriteOperation.execute(
MixedBulkWriteOperation.java:75)
at com.mongodb.Mongo.execute(Mongo.java:827)
at com.mongodb.Mongo$2.execute(Mongo.java:810)
at com.mongodb.MongoCollectionImpl.executeSingleWriteRequest(
MongoCollectionImpl.java:515)
at com.mongodb.MongoCollectionImpl.update(
MongoCollectionImpl.java:508)
at com.mongodb.MongoCollectionImpl.updateOne(
MongoCollectionImpl.java:355)
at com.test.db.mongoDB.RetryingMongoCollection.updateOne(
RetryingMongoCollection.java:909)
and continues failing all the time...
I use mongoDB ver 3.0.6
Mongo java client 3.3.0
Please support.
--
You received this message because you are subscribed to the Google Groups "mongodb-user"
group.
https://docs.mongodb.com/manual/support/
---
You received this message because you are subscribed to the Google Groups
"mongodb-user" group.
To unsubscribe from this group and stop receiving emails from it, send an
Visit this group at https://groups.google.com/group/mongodb-user.
To view this discussion on the web visit https://groups.google.com/d/
msgid/mongodb-user/9d591c09-7fd7-4177-a3b9-91f16966163b%40googlegroups.com
<https://groups.google.com/d/msgid/mongodb-user/9d591c09-7fd7-4177-a3b9-91f16966163b%40googlegroups.com?utm_medium=email&utm_source=footer>
.
For more options, visit https://groups.google.com/d/optout.
--
*{* name : "Ross Lawley",
title : "Senior Software Engineer",
location : "London, UK",
twitter : ["@RossC0 <http://twitter.com/rossc0>", "@MongoDB
<https://twitter.com/mongodb>"],
facebook :"MongoDB
<https://www.google.com/url?q=https%3A%2F%2Fwww.facebook.com%2Fmongodb&sa=D&sntz=1&usg=AFQjCNGPMcaFBzmWsh-MpaWeTH6vMQoDIg>
"*}*
--
You received this message because you are subscribed to the Google Groups "mongodb-user"
group.

For other MongoDB technical support options, see: https://docs.mongodb.com/manual/support/
---
You received this message because you are subscribed to the Google Groups "mongodb-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mongodb-user+***@googlegroups.com.
To post to this group, send email to mongodb-***@googlegroups.com.
Visit this group at https://groups.google.com/group/mongodb-user.
To view this discussion on the web visit https://groups.google.com/d/msgid/mongodb-user/CAOjLY%2BH96cAp%3D%3DsJNzGJ9U8mKthkHGnCwyroZpnfBzKPNJQ4vQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.
'Jeff Yemin' via mongodb-user
2016-12-14 17:24:12 UTC
Permalink
I wasn't able to find a related report in the JAVA project in Jira. Were
you able to find a solution to this?

If not, please post the source code of
com.test.db.mongoDB.RetryingMongoCollection and someone can take a look to
make sure there are logic errors. In particular, I'd like to see what the
setCollection() method does. Another possibility is that this class is
being used in a multi-threaded environment and it's not multi-thread safe.


Regards,
Jeff
Post by Ross Lawley
Hi EG,
https://jira.mongodb.org/browse/JAVA and we'll follow up the discussion
there.
Many thanks,
Ross
Post by EG
I have an application that pulls data from one source and then upserts it
to MongoDB. Sometimes the pulling process takes a lot of time and when app
tries to push a row to MongoDB the following exception is raised probably
com.mongodb.MongoSocketReadException: Prematurely reached end of stream
at com.mongodb.connection.SocketStream.read(SocketStream.java:88)
at
com.mongodb.connection.InternalStreamConnection.receiveResponseBuffers(InternalStreamConnection.java:492)
at
com.mongodb.connection.InternalStreamConnection.receiveMessage(InternalStreamConnection.java:222)
at
com.mongodb.connection.UsageTrackingInternalConnection.receiveMessage(UsageTrackingInternalConnection.java:105)
at
com.mongodb.connection.DefaultConnectionPool$PooledConnection.receiveMessage(DefaultConnectionPool.java:438)
at
com.mongodb.connection.WriteCommandProtocol.receiveMessage(WriteCommandProtocol.java:262)
at
com.mongodb.connection.WriteCommandProtocol.execute(WriteCommandProtocol.java:104)
at
com.mongodb.connection.UpdateCommandProtocol.execute(UpdateCommandProtocol.java:64)
at
com.mongodb.connection.UpdateCommandProtocol.execute(UpdateCommandProtocol.java:37)
at
com.mongodb.connection.DefaultServer$DefaultServerProtocolExecutor.execute(DefaultServer.java:168)
at
com.mongodb.connection.DefaultServerConnection.executeProtocol(DefaultServerConnection.java:289)
at
com.mongodb.connection.DefaultServerConnection.updateCommand(DefaultServerConnection.java:143)
at
com.mongodb.operation.MixedBulkWriteOperation$Run$3.executeWriteCommandProtocol(MixedBulkWriteOperation.java:481)
at
com.mongodb.operation.MixedBulkWriteOperation$Run$RunExecutor.execute(MixedBulkWriteOperation.java:647)
at
com.mongodb.operation.MixedBulkWriteOperation$Run.execute(MixedBulkWriteOperation.java:400)
at
com.mongodb.operation.MixedBulkWriteOperation$1.call(MixedBulkWriteOperation.java:180)
at
com.mongodb.operation.MixedBulkWriteOperation$1.call(MixedBulkWriteOperation.java:169)
at
com.mongodb.operation.OperationHelper.withConnectionSource(OperationHelper.java:232)
at
com.mongodb.operation.OperationHelper.withConnection(OperationHelper.java:223)
at
com.mongodb.operation.MixedBulkWriteOperation.execute(MixedBulkWriteOperation.java:169)
at
com.mongodb.operation.MixedBulkWriteOperation.execute(MixedBulkWriteOperation.java:75)
at com.mongodb.Mongo.execute(Mongo.java:827)
at com.mongodb.Mongo$2.execute(Mongo.java:810)
at
com.mongodb.MongoCollectionImpl.executeSingleWriteRequest(MongoCollectionImpl.java:515)
at
com.mongodb.MongoCollectionImpl.update(MongoCollectionImpl.java:508)
at
com.mongodb.MongoCollectionImpl.updateOne(MongoCollectionImpl.java:355)
at
com.test.db.mongoDB.RetryingMongoCollection.updateOne(RetryingMongoCollection.java:909)
There is a wrapper for MongoCollection class that for each MongoException
and now for java.lang.IllegalStateException thrown
@Override
public UpdateResult updateOne(Bson filter, Bson update,
UpdateOptions updateOptions) {
UpdateResult retVal = null;
final ExceptionHelper ex = new ExceptionHelper(CAConstants.RETRIES,
ErrorType.ERROR, true);
boolean isDone = false;
while (!isDone) {
try {
retVal = proxied.updateOne(filter, update, updateOptions);
isDone = true;
} catch (final MongoException | IllegalStateException e) {
ex.logIfZero("Failed to launch MongoDB operation", e);
if (ex.lastTry()) {
isDone = true;
Log.error("Failed to launch MongoDB operation.", e);
} else {
Log.error("[MDB] Going to update mongo instance due to exception", e);
db = MongoDBFactory.getUpdatedMongoDBInstance();
setCollection();
}
}
}
return retVal;
}
if ( mongoClient != null ) {
try {
mongoClient.close();
} catch (Exception e) {
Log.error("Mongo client throws exception while closing connection", e);
}
...
mongoClient = new MongoClient(servers, Arrays.asList(credential),
new MongoClientOptions.Builder()
.requiredReplicaSetName(REPLICASET_NAME)
.connectTimeout(0)
.connectionsPerHost(CONNECTION_PER_HOST)
.cursorFinalizerEnabled(false)
.build());
db = mongoClient.getDatabase(database);
However, when the mongoClient is updated after
"com.mongodb.MongoSocketReadException: Prematurely reached end of stream"
java.lang.IllegalStateException: state should be: open
at com.mongodb.assertions.Assertions.isTrue(Assertions.java:70)
at
com.mongodb.connection.BaseCluster.selectServer(BaseCluster.java:82)
at
com.mongodb.binding.ClusterBinding$ClusterBindingConnectionSource.<init>(ClusterBinding.java:75)
at
com.mongodb.binding.ClusterBinding$ClusterBindingConnectionSource.<init>(ClusterBinding.java:71)
at
com.mongodb.binding.ClusterBinding.getWriteConnectionSource(ClusterBinding.java:68)
at
com.mongodb.operation.OperationHelper.withConnection(OperationHelper.java:221)
at
com.mongodb.operation.MixedBulkWriteOperation.execute(MixedBulkWriteOperation.java:169)
at
com.mongodb.operation.MixedBulkWriteOperation.execute(MixedBulkWriteOperation.java:75)
at com.mongodb.Mongo.execute(Mongo.java:827)
at com.mongodb.Mongo$2.execute(Mongo.java:810)
at
com.mongodb.MongoCollectionImpl.executeSingleWriteRequest(MongoCollectionImpl.java:515)
at
com.mongodb.MongoCollectionImpl.update(MongoCollectionImpl.java:508)
at
com.mongodb.MongoCollectionImpl.updateOne(MongoCollectionImpl.java:355)
at
com.test.db.mongoDB.RetryingMongoCollection.updateOne(RetryingMongoCollection.java:909)
and continues failing all the time...
I use mongoDB ver 3.0.6
Mongo java client 3.3.0
Please support.
--
You received this message because you are subscribed to the Google Groups "mongodb-user"
group.
https://docs.mongodb.com/manual/support/
---
You received this message because you are subscribed to the Google Groups
"mongodb-user" group.
To unsubscribe from this group and stop receiving emails from it, send an
Visit this group at https://groups.google.com/group/mongodb-user.
To view this discussion on the web visit
https://groups.google.com/d/msgid/mongodb-user/9d591c09-7fd7-4177-a3b9-91f16966163b%40googlegroups.com
<https://groups.google.com/d/msgid/mongodb-user/9d591c09-7fd7-4177-a3b9-91f16966163b%40googlegroups.com?utm_medium=email&utm_source=footer>
.
For more options, visit https://groups.google.com/d/optout.
--
*{* name : "Ross Lawley",
title : "Senior Software Engineer",
location : "London, UK",
<https://twitter.com/mongodb>"],
facebook :"MongoDB
<https://www.google.com/url?q=https%3A%2F%2Fwww.facebook.com%2Fmongodb&sa=D&sntz=1&usg=AFQjCNGPMcaFBzmWsh-MpaWeTH6vMQoDIg>
"*}*
--
You received this message because you are subscribed to the Google Groups "mongodb-user"
group.

For other MongoDB technical support options, see: https://docs.mongodb.com/manual/support/
---
You received this message because you are subscribed to the Google Groups "mongodb-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mongodb-user+***@googlegroups.com.
To post to this group, send email to mongodb-***@googlegroups.com.
Visit this group at https://groups.google.com/group/mongodb-user.
To view this discussion on the web visit https://groups.google.com/d/msgid/mongodb-user/6d65fd2b-2785-49f9-b747-c59d7a17b180%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
EG
2016-12-15 19:06:03 UTC
Permalink
Hi Jeff & Ross,

I have created a JIRA ticket: https://jira.mongodb.org/browse/JAVA-2411 and
provided the requested info.

Furthermore, today I guess I figured out the reason for the initial issue -
"Prematurely reached end of stream". I figured out that this issue occured
exactly at the same time when MongoDB replica set members interchanged in
their roles: PRIMARY & SECONDARY.
While it is not resolves the issue I reported it brings me to another
question: whether java driver has to figure out the situation when replica
set member it has open a socket to turns to be a SECONDARY instead of
PRIMARY and the new socket to the PRIMARY member has to be created?

Thank you a lot,
EG
Post by 'Jeff Yemin' via mongodb-user
I wasn't able to find a related report in the JAVA project in Jira. Were
you able to find a solution to this?
If not, please post the source code of
com.test.db.mongoDB.RetryingMongoCollection and someone can take a look to
make sure there are logic errors. In particular, I'd like to see what the
setCollection() method does. Another possibility is that this class is
being used in a multi-threaded environment and it's not multi-thread safe.
Regards,
Jeff
Post by Ross Lawley
Hi EG,
https://jira.mongodb.org/browse/JAVA and we'll follow up the discussion
there.
Many thanks,
Ross
Post by EG
I have an application that pulls data from one source and then upserts
it to MongoDB. Sometimes the pulling process takes a lot of time and when
app tries to push a row to MongoDB the following exception is raised
com.mongodb.MongoSocketReadException: Prematurely reached end of stream
at com.mongodb.connection.SocketStream.read(SocketStream.java:88)
at
com.mongodb.connection.InternalStreamConnection.receiveResponseBuffers(InternalStreamConnection.java:492)
at
com.mongodb.connection.InternalStreamConnection.receiveMessage(InternalStreamConnection.java:222)
at
com.mongodb.connection.UsageTrackingInternalConnection.receiveMessage(UsageTrackingInternalConnection.java:105)
at
com.mongodb.connection.DefaultConnectionPool$PooledConnection.receiveMessage(DefaultConnectionPool.java:438)
at
com.mongodb.connection.WriteCommandProtocol.receiveMessage(WriteCommandProtocol.java:262)
at
com.mongodb.connection.WriteCommandProtocol.execute(WriteCommandProtocol.java:104)
at
com.mongodb.connection.UpdateCommandProtocol.execute(UpdateCommandProtocol.java:64)
at
com.mongodb.connection.UpdateCommandProtocol.execute(UpdateCommandProtocol.java:37)
at
com.mongodb.connection.DefaultServer$DefaultServerProtocolExecutor.execute(DefaultServer.java:168)
at
com.mongodb.connection.DefaultServerConnection.executeProtocol(DefaultServerConnection.java:289)
at
com.mongodb.connection.DefaultServerConnection.updateCommand(DefaultServerConnection.java:143)
at
com.mongodb.operation.MixedBulkWriteOperation$Run$3.executeWriteCommandProtocol(MixedBulkWriteOperation.java:481)
at
com.mongodb.operation.MixedBulkWriteOperation$Run$RunExecutor.execute(MixedBulkWriteOperation.java:647)
at
com.mongodb.operation.MixedBulkWriteOperation$Run.execute(MixedBulkWriteOperation.java:400)
at
com.mongodb.operation.MixedBulkWriteOperation$1.call(MixedBulkWriteOperation.java:180)
at
com.mongodb.operation.MixedBulkWriteOperation$1.call(MixedBulkWriteOperation.java:169)
at
com.mongodb.operation.OperationHelper.withConnectionSource(OperationHelper.java:232)
at
com.mongodb.operation.OperationHelper.withConnection(OperationHelper.java:223)
at
com.mongodb.operation.MixedBulkWriteOperation.execute(MixedBulkWriteOperation.java:169)
at
com.mongodb.operation.MixedBulkWriteOperation.execute(MixedBulkWriteOperation.java:75)
at com.mongodb.Mongo.execute(Mongo.java:827)
at com.mongodb.Mongo$2.execute(Mongo.java:810)
at
com.mongodb.MongoCollectionImpl.executeSingleWriteRequest(MongoCollectionImpl.java:515)
at
com.mongodb.MongoCollectionImpl.update(MongoCollectionImpl.java:508)
at
com.mongodb.MongoCollectionImpl.updateOne(MongoCollectionImpl.java:355)
at
com.test.db.mongoDB.RetryingMongoCollection.updateOne(RetryingMongoCollection.java:909)
There is a wrapper for MongoCollection class that for each
MongoException and now for java.lang.IllegalStateException thrown
@Override
public UpdateResult updateOne(Bson filter, Bson update,
UpdateOptions updateOptions) {
UpdateResult retVal = null;
final ExceptionHelper ex = new ExceptionHelper(CAConstants.RETRIES,
ErrorType.ERROR, true);
boolean isDone = false;
while (!isDone) {
try {
retVal = proxied.updateOne(filter, update, updateOptions);
isDone = true;
} catch (final MongoException | IllegalStateException e) {
ex.logIfZero("Failed to launch MongoDB operation", e);
if (ex.lastTry()) {
isDone = true;
Log.error("Failed to launch MongoDB operation.", e);
} else {
Log.error("[MDB] Going to update mongo instance due to exception", e);
db = MongoDBFactory.getUpdatedMongoDBInstance();
setCollection();
}
}
}
return retVal;
}
if ( mongoClient != null ) {
try {
mongoClient.close();
} catch (Exception e) {
Log.error("Mongo client throws exception while closing connection", e);
}
...
mongoClient = new MongoClient(servers, Arrays.asList(credential),
new MongoClientOptions.Builder()
.requiredReplicaSetName(REPLICASET_NAME)
.connectTimeout(0)
.connectionsPerHost(CONNECTION_PER_HOST)
.cursorFinalizerEnabled(false)
.build());
db = mongoClient.getDatabase(database);
However, when the mongoClient is updated after
"com.mongodb.MongoSocketReadException: Prematurely reached end of stream"
java.lang.IllegalStateException: state should be: open
at com.mongodb.assertions.Assertions.isTrue(Assertions.java:70)
at
com.mongodb.connection.BaseCluster.selectServer(BaseCluster.java:82)
at
com.mongodb.binding.ClusterBinding$ClusterBindingConnectionSource.<init>(ClusterBinding.java:75)
at
com.mongodb.binding.ClusterBinding$ClusterBindingConnectionSource.<init>(ClusterBinding.java:71)
at
com.mongodb.binding.ClusterBinding.getWriteConnectionSource(ClusterBinding.java:68)
at
com.mongodb.operation.OperationHelper.withConnection(OperationHelper.java:221)
at
com.mongodb.operation.MixedBulkWriteOperation.execute(MixedBulkWriteOperation.java:169)
at
com.mongodb.operation.MixedBulkWriteOperation.execute(MixedBulkWriteOperation.java:75)
at com.mongodb.Mongo.execute(Mongo.java:827)
at com.mongodb.Mongo$2.execute(Mongo.java:810)
at
com.mongodb.MongoCollectionImpl.executeSingleWriteRequest(MongoCollectionImpl.java:515)
at
com.mongodb.MongoCollectionImpl.update(MongoCollectionImpl.java:508)
at
com.mongodb.MongoCollectionImpl.updateOne(MongoCollectionImpl.java:355)
at
com.test.db.mongoDB.RetryingMongoCollection.updateOne(RetryingMongoCollection.java:909)
and continues failing all the time...
I use mongoDB ver 3.0.6
Mongo java client 3.3.0
Please support.
--
You received this message because you are subscribed to the Google
Groups "mongodb-user"
group.
https://docs.mongodb.com/manual/support/
---
You received this message because you are subscribed to the Google
Groups "mongodb-user" group.
To unsubscribe from this group and stop receiving emails from it, send
<javascript:>.
Visit this group at https://groups.google.com/group/mongodb-user.
To view this discussion on the web visit
https://groups.google.com/d/msgid/mongodb-user/9d591c09-7fd7-4177-a3b9-91f16966163b%40googlegroups.com
<https://groups.google.com/d/msgid/mongodb-user/9d591c09-7fd7-4177-a3b9-91f16966163b%40googlegroups.com?utm_medium=email&utm_source=footer>
.
For more options, visit https://groups.google.com/d/optout.
--
*{* name : "Ross Lawley",
title : "Senior Software Engineer",
location : "London, UK",
<https://twitter.com/mongodb>"],
facebook :"MongoDB
<https://www.google.com/url?q=https%3A%2F%2Fwww.facebook.com%2Fmongodb&sa=D&sntz=1&usg=AFQjCNGPMcaFBzmWsh-MpaWeTH6vMQoDIg>
"*}*
--
You received this message because you are subscribed to the Google Groups "mongodb-user"
group.

For other MongoDB technical support options, see: https://docs.mongodb.com/manual/support/
---
You received this message because you are subscribed to the Google Groups "mongodb-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mongodb-user+***@googlegroups.com.
To post to this group, send email to mongodb-***@googlegroups.com.
Visit this group at https://groups.google.com/group/mongodb-user.
To view this discussion on the web visit https://groups.google.com/d/msgid/mongodb-user/1cabd90f-4f7e-4d87-86ba-6a7d39386e2d%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
gossalfredo via mongodb-user
2016-12-15 21:25:48 UTC
Permalink
--------------------------------------------
On Thu, 12/15/16, EG <***@cloudally.com> wrote:

Subject: Re: [mongodb-user] MongoDB: java.lang.IllegalStateException: state should be: open
To: "mongodb-user" <mongodb-***@googlegroups.com>
Date: Thursday, December 15, 2016, 9:06 PM

Hi Jeff & Ross,

I have created a JIRA ticket:
https://jira.mongodb.org/browse/JAVA-2411 and provided the
requested info.

Furthermore, today I guess I figured out the reason for the
initial issue - "Prematurely reached end of
stream". I figured out that this issue occured exactly
at the same time when MongoDB replica set members
interchanged in their roles: PRIMARY & SECONDARY.
While it is not resolves the issue I reported it brings me
to another question: whether java driver has to figure out
the situation when replica set member it has open a socket
to turns to be a SECONDARY instead of PRIMARY and the new
socket to the PRIMARY member has to be created?

Thank you a lot,
EG


On Wednesday, December 14, 2016 at 7:24:12 PM UTC+2, Jeff
Yemin wrote:I wasn't able to
find a related report in the JAVA project in Jira.  Were
you able to find a solution to this?

If not, please post the source code of com.test.db.mongoDB.
RetryingMongoCollection and someone can take a look to make
sure there are logic errors.  In particular, I'd like
to see what the setCollection() method does.  Another
possibility is that this class is being used in a
multi-threaded environment and it's not multi-thread
safe.

Regards,Jeff

On Tuesday, November 22, 2016 at 6:35:21 AM UTC-5, Ross
Lawley wrote:Hi EG,
Can I ask you to file a ticket in Jira: https://jira.mongodb.org/
browse/JAVA  and we'll follow up the discussion
there.
Many thanks,
Ross
On Tue, Nov 22, 2016
at 7:27 AM, EG <***@cloudally.com> wrote:
I have an application that pulls data from
one source and then upserts it to MongoDB. Sometimes the
pulling process takes a lot of time and when app tries to
push a row to MongoDB the following exception is raised
probably to the timeout issue:
    com.mongodb. MongoSocketReadException:
Prematurely reached end of stream    at
com.mongodb.connection. SocketStream.read(
SocketStream.java:88)    at
com.mongodb.connection. InternalStreamConnection.
receiveResponseBuffers( InternalStreamConnection.java:
492)    at
com.mongodb.connection. InternalStreamConnection.
receiveMessage( InternalStreamConnection.java:
222)    at
com.mongodb.connection. UsageTrackingInternalConnectio
n.receiveMessage( UsageTrackingInternalConnectio
n.java:105)    at
com.mongodb.connection. DefaultConnectionPool$
PooledConnection. receiveMessage(
DefaultConnectionPool.java: 438)    at
com.mongodb.connection. WriteCommandProtocol.
receiveMessage( WriteCommandProtocol.java:262) 
  at
com.mongodb.connection. WriteCommandProtocol.execute(
WriteCommandProtocol.java:104)    at
com.mongodb.connection. UpdateCommandProtocol.execute(
UpdateCommandProtocol.java:64)    at
com.mongodb.connection. UpdateCommandProtocol.execute(
UpdateCommandProtocol.java:37)    at
com.mongodb.connection. DefaultServer$
DefaultServerProtocolExecutor. execute(DefaultServer.java:
168)    at
com.mongodb.connection. DefaultServerConnection.
executeProtocol( DefaultServerConnection.java:
289)    at
com.mongodb.connection. DefaultServerConnection.
updateCommand( DefaultServerConnection.java:
143)    at
com.mongodb.operation. MixedBulkWriteOperation$Run$3.
executeWriteCommandProtocol( MixedBulkWriteOperation.java:
481)    at
com.mongodb.operation. MixedBulkWriteOperation$Run$
RunExecutor.execute( MixedBulkWriteOperation.java:
647)    at
com.mongodb.operation. MixedBulkWriteOperation$Run. execute(
MixedBulkWriteOperation.java: 400)    at
com.mongodb.operation. MixedBulkWriteOperation$1.
call(MixedBulkWriteOperation. java:180)   
at
com.mongodb.operation. MixedBulkWriteOperation$1.
call(MixedBulkWriteOperation. java:169)   
at
com.mongodb.operation. OperationHelper.
withConnectionSource( OperationHelper.java:232) 
  at
com.mongodb.operation. OperationHelper. withConnection(
OperationHelper.java:223)    at
com.mongodb.operation. MixedBulkWriteOperation. execute(
MixedBulkWriteOperation.java: 169)    at
com.mongodb.operation. MixedBulkWriteOperation. execute(
MixedBulkWriteOperation.java: 75)    at
com.mongodb.Mongo.execute( Mongo.java:827)   
at
com.mongodb.Mongo$2.execute( Mongo.java:810)   
at com.mongodb.
MongoCollectionImpl. executeSingleWriteRequest(
MongoCollectionImpl.java:515)    at com.mongodb.
MongoCollectionImpl.update(
MongoCollectionImpl.java:508)    at com.mongodb.
MongoCollectionImpl.updateOne(
MongoCollectionImpl.java:355)    at
com.test.db.mongoDB. RetryingMongoCollection. updateOne(
RetryingMongoCollection.java: 909)
There is a wrapper for MongoCollection class that
for each MongoException and now for java.lang.
IllegalStateException thrown
    @Override    public
UpdateResult updateOne(Bson filter, Bson
update,    UpdateOptions
updateOptions) {    UpdateResult retVal =
null;    final ExceptionHelper
ex = new ExceptionHelper(CAConstants. RETRIES,
ErrorType.ERROR, true);    boolean isDone =
false;    while (!isDone)
{    try {   
retVal =
proxied.updateOne(filter, update,
updateOptions);    isDone =
true;    } catch (final
MongoException | IllegalStateException e) {   
ex.logIfZero("Failed
to launch MongoDB operation", e);    if (ex.lastTry())
{    isDone =
true;    Log.error("Failed
to launch MongoDB operation.", e);   
} else
{    Log.error("[MDB]
Going to update mongo instance due to exception",
e);    db =
MongoDBFactory. getUpdatedMongoDBInstance();   
setCollection(); 
  }   

  }   
return
retVal;    }
 tries to reload MongoClient:
    if ( mongoClient !=
null ) {    try { 
  mongoClient.close(); 
  } catch
(Exception e) {    Log.error("Mongo
client throws exception while closing connection",
e);    }   
...    mongoClient = new
MongoClient(servers,
Arrays.asList(credential),     new
MongoClientOptions.Builder()    .requiredReplicaSetName(
REPLICASET_NAME)    .connectTimeout(0) 
  .connectionsPerHost(
CONNECTION_PER_HOST)    .cursorFinalizerEnabled(false) 
  .build()); 
     
db =
mongoClient.getDatabase( database);

However, when the mongoClient is updated after
"com.mongodb. MongoSocketReadException: Prematurely
reached end of stream" it fails with:
    java.lang. IllegalStateException: state
should be: open    at
com.mongodb.assertions. Assertions.isTrue(Assertions.
java:70)    at
com.mongodb.connection. BaseCluster.selectServer(
BaseCluster.java:82)    at
com.mongodb.binding. ClusterBinding$
ClusterBindingConnectionSource
.<init>(ClusterBinding.java: 75)    at
com.mongodb.binding. ClusterBinding$
ClusterBindingConnectionSource
.<init>(ClusterBinding.java: 71)    at
com.mongodb.binding. ClusterBinding.
getWriteConnectionSource(
ClusterBinding.java:68)    at
com.mongodb.operation. OperationHelper. withConnection(
OperationHelper.java:221)    at
com.mongodb.operation. MixedBulkWriteOperation. execute(
MixedBulkWriteOperation.java: 169)    at
com.mongodb.operation. MixedBulkWriteOperation. execute(
MixedBulkWriteOperation.java: 75)    at
com.mongodb.Mongo.execute( Mongo.java:827)   
at
com.mongodb.Mongo$2.execute( Mongo.java:810)   
at com.mongodb.
MongoCollectionImpl. executeSingleWriteRequest(
MongoCollectionImpl.java:515)    at com.mongodb.
MongoCollectionImpl.update(
MongoCollectionImpl.java:508)    at com.mongodb.
MongoCollectionImpl.updateOne(
MongoCollectionImpl.java:355)    at
com.test.db.mongoDB. RetryingMongoCollection. updateOne(
RetryingMongoCollection.java: 909)
and continues failing all the time...
I use mongoDB ver 3.0.6Mongo java
client 3.3.0
Please support.



--

You received this message because you are subscribed to the
Google Groups "mongodb-user"

group.

 

For other MongoDB technical support options, see: https://docs.mongodb.com/
manual/support/

---

You received this message because you are subscribed to the
Google Groups "mongodb-user" group.

To unsubscribe from this group and stop receiving emails
from it, send an email to mongodb-user...@
googlegroups.com.

To post to this group, send email to ***@googlegroups.com.

Visit this group at https://groups.google.com/
group/mongodb-user.

To view this discussion on the web visit https://groups.google.com/d/
msgid/mongodb-user/9d591c09- 7fd7-4177-a3b9-91f16966163b%
40googlegroups.com.

For more options, visit https://groups.google.com/d/
optout.




--

{ name     : "Ross
Lawley",
  title    : "Senior
Software Engineer",
  location : "London,
UK",
 
twitter  : ["@RossC0", "@MongoDB"],
  facebook :"MongoDB"}





--

You received this message because you are subscribed to the
Google Groups "mongodb-user"

group.

 

For other MongoDB technical support options, see: https://docs.mongodb.com/manual/support/

---

You received this message because you are subscribed to the
Google Groups "mongodb-user" group.

To unsubscribe from this group and stop receiving emails
from it, send an email to mongodb-user+***@googlegroups.com.

To post to this group, send email to mongodb-***@googlegroups.com.

Visit this group at https://groups.google.com/group/mongodb-user.

To view this discussion on the web visit https://groups.google.com/d/msgid/mongodb-user/1cabd90f-4f7e-4d87-86ba-6a7d39386e2d%40googlegroups.com.

For more options, visit https://groups.google.com/d/optout.
2 oct - Romania semneaza pactul de la Nyon 20 dec - Alegeri parlamentare Nici un partid nu obtine numarul de voturi necesar pentru a forma guvernul Instaurarea guvernului minoritar Goga-Cuza
--
You received this message because you are subscribed to the Google Groups "mongodb-user"
group.

For other MongoDB technical support options, see: https://docs.mongodb.com/manual/support/
---
You received this message because you are subscribed to the Google Groups "mongodb-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mongodb-user+***@googlegroups.com.
To post to this group, send email to mongodb-***@googlegroups.com.
Visit this group at https://groups.google.com/group/mongodb-user.
To view this discussion on the web visit https://groups.google.com/d/msgid/mongodb-user/546356303.5666023.1481837148408%40mail.yahoo.com.
For more options, visit https://groups.google.com/d/optout.
gossalfredo via mongodb-user
2016-12-15 23:44:08 UTC
Permalink
--------------------------------------------
On Thu, 12/15/16, gossalfredo via mongodb-user <mongodb-***@googlegroups.com> wrote:

Subject: Re: [mongodb-user] MongoDB: java.lang.IllegalStateException: state should be: open
To: mongodb-***@googlegroups.com
Date: Thursday, December 15, 2016, 11:25 PM


--------------------------------------------
On Thu, 12/15/16, EG <***@cloudally.com>
wrote:

Subject: Re: [mongodb-user] MongoDB:
java.lang.IllegalStateException: state should be: open
To: "mongodb-user" <mongodb-***@googlegroups.com>
Date: Thursday, December 15, 2016, 9:06 PM

Hi Jeff & Ross,

I have created a JIRA ticket:
https://jira.mongodb.org/browse/JAVA-2411
and provided the
requested info.

Furthermore, today I guess I figured out the reason for
the
initial issue - "Prematurely reached end of
stream". I figured out that this issue occured exactly
at the same time when MongoDB replica set members
interchanged in their roles: PRIMARY & SECONDARY.
While it is not resolves the issue I reported it brings me
to another question: whether java driver has to figure out
the situation when replica set member it has open a socket
to turns to be a SECONDARY instead of PRIMARY and the new
socket to the PRIMARY member has to be created?

Thank you a lot,
EG


On Wednesday, December 14, 2016 at 7:24:12 PM UTC+2, Jeff
Yemin wrote:I wasn't able to
find a related report in the JAVA project in Jira.  Were
you able to find a solution to this?

If not, please post the source code of
com.test.db.mongoDB.
RetryingMongoCollection and someone can take a look to
make
sure there are logic errors.  In particular, I'd like
to see what the setCollection() method does.  Another
possibility is that this class is being used in a
multi-threaded environment and it's not multi-thread
safe.

Regards,Jeff

On Tuesday, November 22, 2016 at 6:35:21 AM UTC-5, Ross
Lawley wrote:Hi EG,
Can I ask you to file a ticket in Jira: https://jira.mongodb.org/
browse/JAVA  and we'll follow up the discussion
there.
Many thanks,
Ross
On Tue, Nov 22, 2016
at 7:27 AM, EG <***@cloudally.com>
wrote:
I have an application that pulls data from
one source and then upserts it to MongoDB. Sometimes the
pulling process takes a lot of time and when app tries to
push a row to MongoDB the following exception is raised
probably to the timeout issue:
    com.mongodb. MongoSocketReadException:
Prematurely reached end of stream       
at
com.mongodb.connection. SocketStream.read(
SocketStream.java:88)        at
com.mongodb.connection. InternalStreamConnection.
receiveResponseBuffers( InternalStreamConnection.java:
492)        at
com.mongodb.connection. InternalStreamConnection.
receiveMessage( InternalStreamConnection.java:
222)        at
com.mongodb.connection. UsageTrackingInternalConnectio
n.receiveMessage( UsageTrackingInternalConnectio
n.java:105)        at
com.mongodb.connection. DefaultConnectionPool$
PooledConnection. receiveMessage(
DefaultConnectionPool.java: 438)       
at
com.mongodb.connection. WriteCommandProtocol.
receiveMessage( WriteCommandProtocol.java:262) 
      at
com.mongodb.connection. WriteCommandProtocol.execute(
WriteCommandProtocol.java:104)        at
com.mongodb.connection. UpdateCommandProtocol.execute(
UpdateCommandProtocol.java:64)        at
com.mongodb.connection. UpdateCommandProtocol.execute(
UpdateCommandProtocol.java:37)        at
com.mongodb.connection. DefaultServer$
DefaultServerProtocolExecutor. execute(DefaultServer.java:
168)        at
com.mongodb.connection. DefaultServerConnection.
executeProtocol( DefaultServerConnection.java:
289)        at
com.mongodb.connection. DefaultServerConnection.
updateCommand( DefaultServerConnection.java:
143)        at
com.mongodb.operation. MixedBulkWriteOperation$Run$3.
executeWriteCommandProtocol( MixedBulkWriteOperation.java:
481)        at
com.mongodb.operation. MixedBulkWriteOperation$Run$
RunExecutor.execute( MixedBulkWriteOperation.java:
647)        at
com.mongodb.operation. MixedBulkWriteOperation$Run.
execute(
MixedBulkWriteOperation.java: 400)       
at
com.mongodb.operation. MixedBulkWriteOperation$1.
call(MixedBulkWriteOperation. java:180)   
    at
com.mongodb.operation. MixedBulkWriteOperation$1.
call(MixedBulkWriteOperation. java:169)   
    at
com.mongodb.operation. OperationHelper.
withConnectionSource( OperationHelper.java:232) 
      at
com.mongodb.operation. OperationHelper. withConnection(
OperationHelper.java:223)        at
com.mongodb.operation. MixedBulkWriteOperation. execute(
MixedBulkWriteOperation.java: 169)       
at
com.mongodb.operation. MixedBulkWriteOperation. execute(
MixedBulkWriteOperation.java: 75)       
at
com.mongodb.Mongo.execute( Mongo.java:827)   
    at
com.mongodb.Mongo$2.execute( Mongo.java:810)   
    at com.mongodb.
MongoCollectionImpl. executeSingleWriteRequest(
MongoCollectionImpl.java:515)        at
com.mongodb.
MongoCollectionImpl.update(
MongoCollectionImpl.java:508)        at
com.mongodb.
MongoCollectionImpl.updateOne(
MongoCollectionImpl.java:355)        at
com.test.db.mongoDB. RetryingMongoCollection. updateOne(
RetryingMongoCollection.java: 909)
There is a wrapper for MongoCollection class that
for each MongoException and now for java.lang.
IllegalStateException thrown
    @Override    public
UpdateResult updateOne(Bson filter, Bson
update,           
UpdateOptions
updateOptions) {        UpdateResult
retVal =
null;        final ExceptionHelper
ex = new ExceptionHelper(CAConstants. RETRIES,
ErrorType.ERROR, true);        boolean
isDone =
false;        while (!isDone)
{            try {   
           
retVal =
proxied.updateOne(filter, update,
updateOptions);           
    isDone =
true;            } catch
(final
MongoException | IllegalStateException e) {   
           
ex.logIfZero("Failed
to launch MongoDB operation", e);       
        if (ex.lastTry())
{           
        isDone =
true;           
        Log.error("Failed
to launch MongoDB operation.", e);   
            }
else
{           
        Log.error("[MDB]
Going to update mongo instance due to exception",
e);           
        db =
MongoDBFactory. getUpdatedMongoDBInstance();   
           
    setCollection(); 
             
}   
        } 
      }   
    return
retVal;    }
 tries to reload MongoClient:
            if (
mongoClient !=
null ) {           
    try { 
             
    mongoClient.close(); 
             
} catch
(Exception e) {           
        Log.error("Mongo
client throws exception while closing connection",
e);           
    }   
...            mongoClient
= new
MongoClient(servers,
Arrays.asList(credential),        
           
new
MongoClientOptions.Builder()       
           
    .requiredReplicaSetName(
REPLICASET_NAME)           
           
.connectTimeout(0) 
             
        .connectionsPerHost(
CONNECTION_PER_HOST)       
           
    .cursorFinalizerEnabled(false) 
             
        .build()); 
             
        db =
mongoClient.getDatabase( database);

However, when the mongoClient is updated after
"com.mongodb. MongoSocketReadException: Prematurely
reached end of stream" it fails with:
    java.lang. IllegalStateException: state
should be: open        at
com.mongodb.assertions. Assertions.isTrue(Assertions.
java:70)        at
com.mongodb.connection. BaseCluster.selectServer(
BaseCluster.java:82)        at
com.mongodb.binding. ClusterBinding$
ClusterBindingConnectionSource
.<init>(ClusterBinding.java: 75)   
    at
com.mongodb.binding. ClusterBinding$
ClusterBindingConnectionSource
.<init>(ClusterBinding.java: 71)   
    at
com.mongodb.binding. ClusterBinding.
getWriteConnectionSource(
ClusterBinding.java:68)        at
com.mongodb.operation. OperationHelper. withConnection(
OperationHelper.java:221)        at
com.mongodb.operation. MixedBulkWriteOperation. execute(
MixedBulkWriteOperation.java: 169)       
at
com.mongodb.operation. MixedBulkWriteOperation. execute(
MixedBulkWriteOperation.java: 75)       
at
com.mongodb.Mongo.execute( Mongo.java:827)   
    at
com.mongodb.Mongo$2.execute( Mongo.java:810)   
    at com.mongodb.
MongoCollectionImpl. executeSingleWriteRequest(
MongoCollectionImpl.java:515)        at
com.mongodb.
MongoCollectionImpl.update(
MongoCollectionImpl.java:508)        at
com.mongodb.
MongoCollectionImpl.updateOne(
MongoCollectionImpl.java:355)        at
com.test.db.mongoDB. RetryingMongoCollection. updateOne(
RetryingMongoCollection.java: 909)
and continues failing all the time...
I use mongoDB ver 3.0.6Mongo java
client 3.3.0
Please support.



--

You received this message because you are subscribed to
the
Google Groups "mongodb-user"

group.

 

For other MongoDB technical support options, see: https://docs.mongodb.com/
manual/support/

---

You received this message because you are subscribed to
the
Google Groups "mongodb-user" group.

To unsubscribe from this group and stop receiving emails
from it, send an email to mongodb-user...@
googlegroups.com.

To post to this group, send email to ***@googlegroups.com.

Visit this group at https://groups.google.com/
group/mongodb-user.

To view this discussion on the web visit https://groups.google.com/d/
msgid/mongodb-user/9d591c09- 7fd7-4177-a3b9-91f16966163b%
40googlegroups.com.

For more options, visit https://groups.google.com/d/
optout.




--

{ name     : "Ross
Lawley",
  title    : "Senior
Software Engineer",
  location : "London,
UK",
 
twitter  : ["@RossC0", "@MongoDB"],
  facebook :"MongoDB"}





--

You received this message because you are subscribed to
the
Google Groups "mongodb-user"

group.

 

For other MongoDB technical support options, see: https://docs.mongodb.com/manual/support/

---

You received this message because you are subscribed to
the
Google Groups "mongodb-user" group.

To unsubscribe from this group and stop receiving emails
from it, send an email to mongodb-user+***@googlegroups.com.

To post to this group, send email to mongodb-***@googlegroups.com.

Visit this group at
https://groups.google.com/group/mongodb-user.

To view this discussion on the web visit
https://groups.google.com/d/msgid/mongodb-user/1cabd90f-4f7e-4d87-86ba-6a7d39386e2d%40googlegroups.com.

For more options, visit
https://groups.google.com/d/optout.
2 oct - Romania semneaza pactul de la Nyon 20
dec   - Alegeri 
parlamentare   Nici  un partid nu obtine
numarul de voturi necesar pentru a forma guvernul 
Instaurarea guvernului minoritar Goga-Cuza

--
You received this message because you are subscribed to the
Google Groups "mongodb-user"
group.

For other MongoDB technical support options, see: https://docs.mongodb.com/manual/support/
---
You received this message because you are subscribed to the
Google Groups "mongodb-user" group.
To unsubscribe from this group and stop receiving emails
from it, send an email to mongodb-user+***@googlegroups.com.
To post to this group, send email to mongodb-***@googlegroups.com.
Visit this group at
https://groups.google.com/group/mongodb-user.
To view this discussion on the web visit
https://groups.google.com/d/msgid/mongodb-user/546356303.5666023.1481837148408%40mail.yahoo.com.
For more options, visit
https://groups.google.com/d/optout.a inceputul secolului al XX-lea Romania s-a afirmat in sud-estul Europei in factor de stabilitate politica. Politica externa a incercat sa corespunda pe in si sa urmareasca realizarea intereselor nationale aceasta pe fondul compli-situatiei din Balcani si al conturarii celei de-a doua aliante politico-diplomatice Europa - Antanta Tripla intelegere - constituita de Franta Anglia si Rusia lania a urmarit in principal mentinerea statu-quo-uM in Peninsula Balcanica i acest sens si-a modelat activitatea pe langa Puterile Centrale. Noua situatie sud-estul Europei in special apropierea Austro-Ungariei de Bulgaria si terea agresivitatii sale dupa 1908 cand a anexat Bosnia si Hertegovina s-a ant si asupra situatiei romanilor din Transilvania. Cel din urma eveniment a intuat contradictiile in aceasta zona a continentului dat fiind si faptul ca entiile Rusiei fata de stramtorile Bosfor si Dardanele au fost ignorate la Viena. asemenea Bulgaria si-a manifestat dorinta de a ingloba noi teritorii. De fapt jaria dorea sa-si sporeasca teritoriul pe seama Imperiului Otoman prin aceasta and in pericol statu-quo-u\ balcanic. in aceste conditii s-a produs in mod tat si greu de surprins de cei neavizati o detasare a tarii noastre de Puterile trale. Ea s-a prelungit pana catre 1914 in pragul conflagratiei mondiale.
--
You received this message because you are subscribed to the Google Groups "mongodb-user"
group.

For other MongoDB technical support options, see: https://docs.mongodb.com/manual/support/
---
You received this message because you are subscribed to the Google Groups "mongodb-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mongodb-user+***@googlegroups.com.
To post to this group, send email to mongodb-***@googlegroups.com.
Visit this group at https://groups.google.com/group/mongodb-user.
To view this discussion on the web visit https://groups.google.com/d/msgid/mongodb-user/1254037117.5756327.1481845448907%40mail.yahoo.com.
For more options, visit https://groups.google.com/d/optout.
gossalfredo via mongodb-user
2016-12-16 09:59:45 UTC
Permalink
--------------------------------------------
On Fri, 12/16/16, gossalfredo via mongodb-user <mongodb-***@googlegroups.com> wrote:

Subject: Re: [mongodb-user] MongoDB: java.lang.IllegalStateException: state should be: open
To: mongodb-***@googlegroups.com
Date: Friday, December 16, 2016, 1:44 AM


--------------------------------------------
On Thu, 12/15/16, gossalfredo via mongodb-user <mongodb-***@googlegroups.com>
wrote:

Subject: Re: [mongodb-user] MongoDB:
java.lang.IllegalStateException: state should be: open
To: mongodb-***@googlegroups.com
Date: Thursday, December 15, 2016, 11:25 PM


--------------------------------------------
On Thu, 12/15/16, EG <***@cloudally.com>
wrote:

  Subject: Re: [mongodb-user] MongoDB:
java.lang.IllegalStateException: state should be: open
  To: "mongodb-user" <mongodb-***@googlegroups.com>
  Date: Thursday, December 15, 2016, 9:06 PM
 
  Hi Jeff & Ross,
 
  I have created a JIRA ticket:
  https://jira.mongodb.org/browse/JAVA-2411
and provided the
  requested info.
 
  Furthermore, today I guess I figured out the reason
for
the
  initial issue - "Prematurely reached end of
  stream". I figured out that this issue occured
exactly
  at the same time when MongoDB replica set members
  interchanged in their roles: PRIMARY &
SECONDARY.
  While it is not resolves the issue I reported it
brings me
  to another question: whether java driver has to
figure out
  the situation when replica set member it has open a
socket
  to turns to be a SECONDARY instead of PRIMARY and the
new
  socket to the PRIMARY member has to be created?
 
  Thank you a lot,
  EG
 
 
  On Wednesday, December 14, 2016 at 7:24:12 PM UTC+2,
Jeff
  Yemin wrote:I wasn't able to
  find a related report in the JAVA project in Jira.
 Were
  you able to find a solution to this?
 
  If not, please post the source code of
com.test.db.mongoDB.
  RetryingMongoCollection and someone can take a look
to
make
  sure there are logic errors.  In particular, I'd
like
  to see what the setCollection() method does.
 Another
  possibility is that this class is being used in a
  multi-threaded environment and it's not multi-thread
  safe.
 
  Regards,Jeff
 
  On Tuesday, November 22, 2016 at 6:35:21 AM UTC-5,
Ross
  Lawley wrote:Hi EG,
  Can I ask you to file a ticket in Jira: https://jira.mongodb.org/
  browse/JAVA  and we'll follow up the discussion
  there.
  Many thanks,
  Ross
  On Tue, Nov 22, 2016
  at 7:27 AM, EG <***@cloudally.com>
wrote:
  I have an application that pulls data from
  one source and then upserts it to MongoDB. Sometimes
the
  pulling process takes a lot of time and when app
tries to
  push a row to MongoDB the following exception is
raised
  probably to the timeout issue:
      com.mongodb. MongoSocketReadException:
  Prematurely reached end of stream       
at
  com.mongodb.connection. SocketStream.read(
  SocketStream.java:88)        at
  com.mongodb.connection. InternalStreamConnection.
  receiveResponseBuffers(
InternalStreamConnection.java:
  492)        at
  com.mongodb.connection. InternalStreamConnection.
  receiveMessage( InternalStreamConnection.java:
  222)        at
  com.mongodb.connection.
UsageTrackingInternalConnectio
  n.receiveMessage( UsageTrackingInternalConnectio
  n.java:105)        at
  com.mongodb.connection. DefaultConnectionPool$
  PooledConnection. receiveMessage(
  DefaultConnectionPool.java: 438)       
at
  com.mongodb.connection. WriteCommandProtocol.
  receiveMessage( WriteCommandProtocol.java:262) 
        at
  com.mongodb.connection.
WriteCommandProtocol.execute(
  WriteCommandProtocol.java:104)        at
  com.mongodb.connection.
UpdateCommandProtocol.execute(
  UpdateCommandProtocol.java:64)        at
  com.mongodb.connection.
UpdateCommandProtocol.execute(
  UpdateCommandProtocol.java:37)        at
  com.mongodb.connection. DefaultServer$
  DefaultServerProtocolExecutor.
execute(DefaultServer.java:
  168)        at
  com.mongodb.connection. DefaultServerConnection.
  executeProtocol( DefaultServerConnection.java:
  289)        at
  com.mongodb.connection. DefaultServerConnection.
  updateCommand( DefaultServerConnection.java:
  143)        at
  com.mongodb.operation.
MixedBulkWriteOperation$Run$3.
  executeWriteCommandProtocol(
MixedBulkWriteOperation.java:
  481)        at
  com.mongodb.operation. MixedBulkWriteOperation$Run$
  RunExecutor.execute( MixedBulkWriteOperation.java:
  647)        at
  com.mongodb.operation. MixedBulkWriteOperation$Run.
execute(
  MixedBulkWriteOperation.java: 400)       
at
  com.mongodb.operation. MixedBulkWriteOperation$1.
  call(MixedBulkWriteOperation. java:180)   
      at
  com.mongodb.operation. MixedBulkWriteOperation$1.
  call(MixedBulkWriteOperation. java:169)   
      at
  com.mongodb.operation. OperationHelper.
  withConnectionSource( OperationHelper.java:232) 
        at
  com.mongodb.operation. OperationHelper.
withConnection(
  OperationHelper.java:223)        at
  com.mongodb.operation. MixedBulkWriteOperation.
execute(
  MixedBulkWriteOperation.java: 169)       
at
  com.mongodb.operation. MixedBulkWriteOperation.
execute(
  MixedBulkWriteOperation.java: 75)       
at
  com.mongodb.Mongo.execute( Mongo.java:827)   
      at
  com.mongodb.Mongo$2.execute( Mongo.java:810)   
      at com.mongodb.
  MongoCollectionImpl. executeSingleWriteRequest(
  MongoCollectionImpl.java:515)        at
com.mongodb.
  MongoCollectionImpl.update(
  MongoCollectionImpl.java:508)        at
com.mongodb.
  MongoCollectionImpl.updateOne(
  MongoCollectionImpl.java:355)        at
  com.test.db.mongoDB. RetryingMongoCollection.
updateOne(
  RetryingMongoCollection.java: 909)
  There is a wrapper for MongoCollection class that
  for each MongoException and now for java.lang.
  IllegalStateException thrown
      @Override    public
  UpdateResult updateOne(Bson filter, Bson
  update,           
UpdateOptions
  updateOptions) {        UpdateResult
retVal =
  null;        final ExceptionHelper
  ex = new ExceptionHelper(CAConstants. RETRIES,
  ErrorType.ERROR, true);        boolean
isDone =
  false;        while (!isDone)
  {            try {   
             
retVal =
  proxied.updateOne(filter, update,
  updateOptions);           
    isDone =
  true;            } catch
(final
  MongoException | IllegalStateException e) {   
             
ex.logIfZero("Failed
  to launch MongoDB operation", e);       
        if (ex.lastTry())
  {           
        isDone =
  true;           
        Log.error("Failed
  to launch MongoDB operation.", e);   
              }
else
  {           
        Log.error("[MDB]
  Going to update mongo instance due to exception",
  e);           
        db =
  MongoDBFactory. getUpdatedMongoDBInstance();   
             
    setCollection(); 
               
}   
          } 
        }   
      return
  retVal;    }
   tries to reload MongoClient:
              if (
mongoClient !=
  null ) {           
    try { 
               
    mongoClient.close(); 
               
} catch
  (Exception e) {           
        Log.error("Mongo
  client throws exception while closing connection",
  e);           
    }   
  ...            mongoClient
= new
  MongoClient(servers,
  Arrays.asList(credential),        
           
new
  MongoClientOptions.Builder()       
           
    .requiredReplicaSetName(
  REPLICASET_NAME)           
           
.connectTimeout(0) 
               
        .connectionsPerHost(
  CONNECTION_PER_HOST)       
           
    .cursorFinalizerEnabled(false) 
               
        .build()); 
               
          db =
  mongoClient.getDatabase( database);
 
  However, when the mongoClient is updated after
  "com.mongodb. MongoSocketReadException: Prematurely
  reached end of stream" it fails with:
      java.lang. IllegalStateException: state
  should be: open        at
  com.mongodb.assertions.
Assertions.isTrue(Assertions.
  java:70)        at
  com.mongodb.connection. BaseCluster.selectServer(
  BaseCluster.java:82)        at
  com.mongodb.binding. ClusterBinding$
  ClusterBindingConnectionSource
  .<init>(ClusterBinding.java: 75)   
    at
  com.mongodb.binding. ClusterBinding$
  ClusterBindingConnectionSource
  .<init>(ClusterBinding.java: 71)   
    at
  com.mongodb.binding. ClusterBinding.
  getWriteConnectionSource(
  ClusterBinding.java:68)        at
  com.mongodb.operation. OperationHelper.
withConnection(
  OperationHelper.java:221)        at
  com.mongodb.operation. MixedBulkWriteOperation.
execute(
  MixedBulkWriteOperation.java: 169)       
at
  com.mongodb.operation. MixedBulkWriteOperation.
execute(
  MixedBulkWriteOperation.java: 75)       
at
  com.mongodb.Mongo.execute( Mongo.java:827)   
      at
  com.mongodb.Mongo$2.execute( Mongo.java:810)   
      at com.mongodb.
  MongoCollectionImpl. executeSingleWriteRequest(
  MongoCollectionImpl.java:515)        at
com.mongodb.
  MongoCollectionImpl.update(
  MongoCollectionImpl.java:508)        at
com.mongodb.
  MongoCollectionImpl.updateOne(
  MongoCollectionImpl.java:355)        at
  com.test.db.mongoDB. RetryingMongoCollection.
updateOne(
  RetryingMongoCollection.java: 909)
  and continues failing all the time...
  I use mongoDB ver 3.0.6Mongo java
  client 3.3.0
  Please support.
 
 
 
  --
 
  You received this message because you are subscribed
to
the
  Google Groups "mongodb-user"
 
  group.
 
   
 
  For other MongoDB technical support options, see: https://docs.mongodb.com/
  manual/support/
 
  ---
 
  You received this message because you are subscribed
to
the
  Google Groups "mongodb-user" group.
 
  To unsubscribe from this group and stop receiving
emails
  from it, send an email to mongodb-user...@
  googlegroups.com.
 
  To post to this group, send email to ***@googlegroups.com.
 
  Visit this group at https://groups.google.com/
  group/mongodb-user.
 
  To view this discussion on the web visit https://groups.google.com/d/
  msgid/mongodb-user/9d591c09-
7fd7-4177-a3b9-91f16966163b%
  40googlegroups.com.
 
  For more options, visit https://groups.google.com/d/
  optout.
 
 
 
 
  --
 
  { name     : "Ross
  Lawley",
    title    : "Senior
  Software Engineer",
    location : "London,
  UK",
   
  twitter  : ["@RossC0", "@MongoDB"],
    facebook :"MongoDB"}
 
 
 
 
 
  --
 
  You received this message because you are subscribed
to
the
  Google Groups "mongodb-user"
 
  group.
 
   
 
  For other MongoDB technical support options, see: https://docs.mongodb.com/manual/support/
 
  ---
 
  You received this message because you are subscribed
to
the
  Google Groups "mongodb-user" group.
 
  To unsubscribe from this group and stop receiving
emails
  from it, send an email to mongodb-user+***@googlegroups.com.
 
  To post to this group, send email to mongodb-***@googlegroups.com.
 
  Visit this group at
https://groups.google.com/group/mongodb-user.
 
  To view this discussion on the web visit
https://groups.google.com/d/msgid/mongodb-user/1cabd90f-4f7e-4d87-86ba-6a7d39386e2d%40googlegroups.com.
 
  For more options, visit
https://groups.google.com/d/optout.
  2 oct - Romania semneaza pactul de la Nyon 20
dec   - Alegeri 
parlamentare   Nici  un partid nu obtine
numarul de voturi necesar pentru a forma guvernul 
Instaurarea guvernului minoritar Goga-Cuza

--
You received this message because you are subscribed to
the
Google Groups "mongodb-user"
group.

For other MongoDB technical support options, see: https://docs.mongodb.com/manual/support/
---
You received this message because you are subscribed to
the
Google Groups "mongodb-user" group.
To unsubscribe from this group and stop receiving emails
from it, send an email to mongodb-user+***@googlegroups.com.
To post to this group, send email to mongodb-***@googlegroups.com.
Visit this group at
https://groups.google.com/group/mongodb-user.
To view this discussion on the web visit
https://groups.google.com/d/msgid/mongodb-user/546356303.5666023.1481837148408%40mail.yahoo.com.
For more options, visit
https://groups.google.com/d/optout.a
inceputul secolului al XX-lea Romania s-a afirmat in
sud-estul Europei in factor de stabilitate politica.
Politica externa a incercat sa corespunda pe in si sa
urmareasca realizarea intereselor nationale  aceasta pe
fondul compli-situatiei din Balcani si al conturarii celei
de-a doua aliante politico-diplomatice Europa -
Antanta  Tripla intelegere  - constituita de
Franta  Anglia si Rusia  lania a urmarit  in
principal  mentinerea statu-quo-uM in Peninsula
Balcanica i acest sens  si-a modelat activitatea pe
langa Puterile Centrale. Noua situatie sud-estul
Europei  in special apropierea Austro-Ungariei de
Bulgaria si terea agresivitatii sale dupa 1908  cand a
anexat Bosnia si Hertegovina  s-a ant si asupra
situatiei romanilor din Transilvania. Cel din urma eveniment
a intuat contradictiile in aceasta zona a
continentului  dat fiind si faptul ca entiile Rusiei
fata de stramtorile Bosfor si Dardanele au fost ignorate la
Viena. asemenea  Bulgaria si-a manifestat dorinta de a
ingloba noi teritorii. De fapt  jaria dorea sa-si
sporeasca teritoriul pe seama Imperiului Otoman  prin
aceasta and in pericol statu-quo-u\ balcanic. in aceste
conditii s-a produs  in mod tat si greu de surprins de
cei neavizati  o detasare a tarii noastre de Puterile
trale. Ea s-a prelungit pana catre 1914  in pragul
conflagratiei mondiale.

--
You received this message because you are subscribed to the
Google Groups "mongodb-user"
group.

For other MongoDB technical support options, see: https://docs.mongodb.com/manual/support/
---
You received this message because you are subscribed to the
Google Groups "mongodb-user" group.
To unsubscribe from this group and stop receiving emails
from it, send an email to mongodb-user+***@googlegroups.com.
To post to this group, send email to mongodb-***@googlegroups.com.
Visit this group at
https://groups.google.com/group/mongodb-user.
To view this discussion on the web visit
https://groups.google.com/d/msgid/mongodb-user/1254037117.5756327.1481845448907%40mail.yahoo.com.
For more options, visit
https://groups.google.com/d/optout.rimii ani ai secolului XX au marcat si deschiderea artei romanesti catre universul de idei si forme ale curentului modernist. Opera lui Constantin Brancusi degajand o viziune stilizata a volumelor a fost pentru inceput primita cu reticenta de publicul format si educat artistic in spiritul curentului academismului. Se afirma nume noi ca: A. Verona N. Vermont C. Cutescu-Storck Gh. Petrascu Th. Pallady. in sculptura Ion Georgescusi stefan Valbudea preiau stafeta de la dascalul lor Carol Storck pentru a o preda unei generatii mai tinere: C. Brancusi D. Paciurea Fritz Storck. Activitatea
--
You received this message because you are subscribed to the Google Groups "mongodb-user"
group.

For other MongoDB technical support options, see: https://docs.mongodb.com/manual/support/
---
You received this message because you are subscribed to the Google Groups "mongodb-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mongodb-user+***@googlegroups.com.
To post to this group, send email to mongodb-***@googlegroups.com.
Visit this group at https://groups.google.com/group/mongodb-user.
To view this discussion on the web visit https://groups.google.com/d/msgid/mongodb-user/1587706857.6050716.1481882385190%40mail.yahoo.com.
For more options, visit https://groups.google.com/d/optout.
gossalfredo via mongodb-user
2016-12-16 15:13:20 UTC
Permalink
--------------------------------------------
On Fri, 12/16/16, gossalfredo via mongodb-user <mongodb-***@googlegroups.com> wrote:

Subject: Re: [mongodb-user] MongoDB: java.lang.IllegalStateException: state should be: open
To: mongodb-***@googlegroups.com
Date: Friday, December 16, 2016, 11:59 AM


--------------------------------------------
On Fri, 12/16/16, gossalfredo via mongodb-user <mongodb-***@googlegroups.com>
wrote:

Subject: Re: [mongodb-user] MongoDB:
java.lang.IllegalStateException: state should be: open
To: mongodb-***@googlegroups.com
Date: Friday, December 16, 2016, 1:44 AM


--------------------------------------------
On Thu, 12/15/16, gossalfredo via mongodb-user <mongodb-***@googlegroups.com>
wrote:

  Subject: Re: [mongodb-user] MongoDB:
java.lang.IllegalStateException: state should be: open
  To: mongodb-***@googlegroups.com
  Date: Thursday, December 15, 2016, 11:25 PM
 
 
  --------------------------------------------
  On Thu, 12/15/16, EG <***@cloudally.com>
  wrote:
 
  Subject: Re: [mongodb-user] MongoDB:
  java.lang.IllegalStateException: state should be:
open
  To: "mongodb-user" <mongodb-***@googlegroups.com>
  Date: Thursday, December 15, 2016, 9:06 PM
 
  Hi Jeff & Ross,
 
  I have created a JIRA ticket:
  https://jira.mongodb.org/browse/JAVA-2411
  and provided the
  requested info.
 
  Furthermore, today I guess I figured out the reason
for
  the
  initial issue - "Prematurely reached end of
  stream". I figured out that this issue occured
exactly
  at the same time when MongoDB replica set members
  interchanged in their roles: PRIMARY &
SECONDARY.
  While it is not resolves the issue I reported it
brings me
  to another question: whether java driver has to
figure out
  the situation when replica set member it has open a
socket
  to turns to be a SECONDARY instead of PRIMARY and the
new
  socket to the PRIMARY member has to be created?
 
  Thank you a lot,
  EG
 
 
  On Wednesday, December 14, 2016 at 7:24:12 PM UTC+2,
Jeff
  Yemin wrote:I wasn't able to
  find a related report in the JAVA project in Jira.
 Were
  you able to find a solution to this?
 
  If not, please post the source code of
  com.test.db.mongoDB.
  RetryingMongoCollection and someone can take a look
to
  make
  sure there are logic errors.  In particular, I'd
like
  to see what the setCollection() method does.
 Another
  possibility is that this class is being used in a
  multi-threaded environment and it's not multi-thread
  safe.
 
  Regards,Jeff
 
  On Tuesday, November 22, 2016 at 6:35:21 AM UTC-5,
Ross
  Lawley wrote:Hi EG,
  Can I ask you to file a ticket in Jira: https://jira.mongodb.org/
  browse/JAVA  and we'll follow up the discussion
  there.
  Many thanks,
  Ross
  On Tue, Nov 22, 2016
  at 7:27 AM, EG <***@cloudally.com>
  wrote:
  I have an application that pulls data from
  one source and then upserts it to MongoDB. Sometimes
the
  pulling process takes a lot of time and when app
tries to
  push a row to MongoDB the following exception is
raised
  probably to the timeout issue:
      com.mongodb. MongoSocketReadException:
  Prematurely reached end of stream       
  at
  com.mongodb.connection. SocketStream.read(
  SocketStream.java:88)        at
  com.mongodb.connection. InternalStreamConnection.
  receiveResponseBuffers(
InternalStreamConnection.java:
  492)        at
  com.mongodb.connection. InternalStreamConnection.
  receiveMessage( InternalStreamConnection.java:
  222)        at
  com.mongodb.connection.
UsageTrackingInternalConnectio
  n.receiveMessage( UsageTrackingInternalConnectio
  n.java:105)        at
  com.mongodb.connection. DefaultConnectionPool$
  PooledConnection. receiveMessage(
  DefaultConnectionPool.java: 438)       
  at
  com.mongodb.connection. WriteCommandProtocol.
  receiveMessage( WriteCommandProtocol.java:262) 
        at
  com.mongodb.connection.
WriteCommandProtocol.execute(
  WriteCommandProtocol.java:104)        at
  com.mongodb.connection.
UpdateCommandProtocol.execute(
  UpdateCommandProtocol.java:64)        at
  com.mongodb.connection.
UpdateCommandProtocol.execute(
  UpdateCommandProtocol.java:37)        at
  com.mongodb.connection. DefaultServer$
  DefaultServerProtocolExecutor.
execute(DefaultServer.java:
  168)        at
  com.mongodb.connection. DefaultServerConnection.
  executeProtocol( DefaultServerConnection.java:
  289)        at
  com.mongodb.connection. DefaultServerConnection.
  updateCommand( DefaultServerConnection.java:
  143)        at
  com.mongodb.operation.
MixedBulkWriteOperation$Run$3.
  executeWriteCommandProtocol(
MixedBulkWriteOperation.java:
  481)        at
  com.mongodb.operation. MixedBulkWriteOperation$Run$
  RunExecutor.execute( MixedBulkWriteOperation.java:
  647)        at
  com.mongodb.operation. MixedBulkWriteOperation$Run.
  execute(
  MixedBulkWriteOperation.java: 400)       
  at
  com.mongodb.operation. MixedBulkWriteOperation$1.
  call(MixedBulkWriteOperation. java:180)   
      at
  com.mongodb.operation. MixedBulkWriteOperation$1.
  call(MixedBulkWriteOperation. java:169)   
      at
  com.mongodb.operation. OperationHelper.
  withConnectionSource( OperationHelper.java:232) 
        at
  com.mongodb.operation. OperationHelper.
withConnection(
  OperationHelper.java:223)        at
  com.mongodb.operation. MixedBulkWriteOperation.
execute(
  MixedBulkWriteOperation.java: 169)       
  at
  com.mongodb.operation. MixedBulkWriteOperation.
execute(
  MixedBulkWriteOperation.java: 75)       
  at
  com.mongodb.Mongo.execute( Mongo.java:827)   
      at
  com.mongodb.Mongo$2.execute( Mongo.java:810)   
      at com.mongodb.
  MongoCollectionImpl. executeSingleWriteRequest(
  MongoCollectionImpl.java:515)        at
  com.mongodb.
  MongoCollectionImpl.update(
  MongoCollectionImpl.java:508)        at
  com.mongodb.
  MongoCollectionImpl.updateOne(
  MongoCollectionImpl.java:355)        at
  com.test.db.mongoDB. RetryingMongoCollection.
updateOne(
  RetryingMongoCollection.java: 909)
  There is a wrapper for MongoCollection class that
  for each MongoException and now for java.lang.
  IllegalStateException thrown
      @Override    public
  UpdateResult updateOne(Bson filter, Bson
  update,           
  UpdateOptions
  updateOptions) {        UpdateResult
  retVal =
  null;        final ExceptionHelper
  ex = new ExceptionHelper(CAConstants. RETRIES,
  ErrorType.ERROR, true);        boolean
  isDone =
  false;        while (!isDone)
  {            try {   
             
  retVal =
  proxied.updateOne(filter, update,
  updateOptions);           
      isDone =
  true;            } catch
  (final
  MongoException | IllegalStateException e) {   
             
  ex.logIfZero("Failed
  to launch MongoDB operation", e);       
          if (ex.lastTry())
  {           
          isDone =
  true;           
          Log.error("Failed
  to launch MongoDB operation.", e);   
              }
  else
  {           
          Log.error("[MDB]
  Going to update mongo instance due to exception",
  e);           
          db =
  MongoDBFactory. getUpdatedMongoDBInstance();   
             
      setCollection(); 
               
  }   
          } 
        }   
      return
  retVal;    }
   tries to reload MongoClient:
              if (
  mongoClient !=
  null ) {           
      try { 
               
      mongoClient.close(); 
               
  } catch
  (Exception e) {           
          Log.error("Mongo
  client throws exception while closing connection",
  e);           
      }   
  ...            mongoClient
  = new
  MongoClient(servers,
  Arrays.asList(credential),        
             
  new
  MongoClientOptions.Builder()       
             
      .requiredReplicaSetName(
  REPLICASET_NAME)           
             
  .connectTimeout(0) 
               
          .connectionsPerHost(
  CONNECTION_PER_HOST)       
             
      .cursorFinalizerEnabled(false) 
               
          .build()); 
               
          db =
  mongoClient.getDatabase( database);
 
  However, when the mongoClient is updated after
  "com.mongodb. MongoSocketReadException: Prematurely
  reached end of stream" it fails with:
      java.lang. IllegalStateException: state
  should be: open        at
  com.mongodb.assertions.
Assertions.isTrue(Assertions.
  java:70)        at
  com.mongodb.connection. BaseCluster.selectServer(
  BaseCluster.java:82)        at
  com.mongodb.binding. ClusterBinding$
  ClusterBindingConnectionSource
  .<init>(ClusterBinding.java: 75)   
      at
  com.mongodb.binding. ClusterBinding$
  ClusterBindingConnectionSource
  .<init>(ClusterBinding.java: 71)   
      at
  com.mongodb.binding. ClusterBinding.
  getWriteConnectionSource(
  ClusterBinding.java:68)        at
  com.mongodb.operation. OperationHelper.
withConnection(
  OperationHelper.java:221)        at
  com.mongodb.operation. MixedBulkWriteOperation.
execute(
  MixedBulkWriteOperation.java: 169)       
  at
  com.mongodb.operation. MixedBulkWriteOperation.
execute(
  MixedBulkWriteOperation.java: 75)       
  at
  com.mongodb.Mongo.execute( Mongo.java:827)   
      at
  com.mongodb.Mongo$2.execute( Mongo.java:810)   
      at com.mongodb.
  MongoCollectionImpl. executeSingleWriteRequest(
  MongoCollectionImpl.java:515)        at
  com.mongodb.
  MongoCollectionImpl.update(
  MongoCollectionImpl.java:508)        at
  com.mongodb.
  MongoCollectionImpl.updateOne(
  MongoCollectionImpl.java:355)        at
  com.test.db.mongoDB. RetryingMongoCollection.
updateOne(
  RetryingMongoCollection.java: 909)
  and continues failing all the time...
  I use mongoDB ver 3.0.6Mongo java
  client 3.3.0
  Please support.
 
 
 
  --
 
  You received this message because you are subscribed
to
  the
  Google Groups "mongodb-user"
 
  group.
 
   
 
  For other MongoDB technical support options, see: https://docs.mongodb.com/
  manual/support/
 
  ---
 
  You received this message because you are subscribed
to
  the
  Google Groups "mongodb-user" group.
 
  To unsubscribe from this group and stop receiving
emails
  from it, send an email to mongodb-user...@
  googlegroups.com.
 
  To post to this group, send email to ***@googlegroups.com.
 
  Visit this group at https://groups.google.com/
  group/mongodb-user.
 
  To view this discussion on the web visit https://groups.google.com/d/
  msgid/mongodb-user/9d591c09-
7fd7-4177-a3b9-91f16966163b%
  40googlegroups.com.
 
  For more options, visit https://groups.google.com/d/
  optout.
 
 
 
 
  --
 
  { name     : "Ross
  Lawley",
    title    : "Senior
  Software Engineer",
    location : "London,
  UK",
   
  twitter  : ["@RossC0", "@MongoDB"],
    facebook :"MongoDB"}
 
 
 
 
 
  --
 
  You received this message because you are subscribed
to
  the
  Google Groups "mongodb-user"
 
  group.
 
   
 
  For other MongoDB technical support options, see: https://docs.mongodb.com/manual/support/
 
  ---
 
  You received this message because you are subscribed
to
  the
  Google Groups "mongodb-user" group.
 
  To unsubscribe from this group and stop receiving
emails
  from it, send an email to mongodb-user+***@googlegroups.com.
 
  To post to this group, send email to mongodb-***@googlegroups.com.
 
  Visit this group at
  https://groups.google.com/group/mongodb-user.
 
  To view this discussion on the web visit
 
https://groups.google.com/d/msgid/mongodb-user/1cabd90f-4f7e-4d87-86ba-6a7d39386e2d%40googlegroups.com.
 
  For more options, visit
  https://groups.google.com/d/optout.
  2 oct - Romania semneaza pactul de la Nyon 20
  dec   - Alegeri 
  parlamentare   Nici  un partid nu obtine
  numarul de voturi necesar pentru a forma guvernul 
  Instaurarea guvernului minoritar Goga-Cuza
 
  --
  You received this message because you are subscribed
to
the
  Google Groups "mongodb-user"
  group.
 
  For other MongoDB technical support options, see: https://docs.mongodb.com/manual/support/
  ---
  You received this message because you are subscribed
to
the
  Google Groups "mongodb-user" group.
  To unsubscribe from this group and stop receiving
emails
  from it, send an email to mongodb-user+***@googlegroups.com.
  To post to this group, send email to mongodb-***@googlegroups.com.
  Visit this group at
  https://groups.google.com/group/mongodb-user.
  To view this discussion on the web visit
 
https://groups.google.com/d/msgid/mongodb-user/546356303.5666023.1481837148408%40mail.yahoo.com.
  For more options, visit
  https://groups.google.com/d/optout.a
inceputul secolului al XX-lea Romania s-a afirmat in
sud-estul Europei in factor de stabilitate politica.
Politica externa a incercat sa corespunda pe in si sa
urmareasca realizarea intereselor nationale  aceasta pe
fondul compli-situatiei din Balcani si al conturarii celei
de-a doua aliante politico-diplomatice Europa -
Antanta  Tripla intelegere  - constituita de
Franta  Anglia si Rusia  lania a urmarit  in
principal  mentinerea statu-quo-uM in Peninsula
Balcanica i acest sens  si-a modelat activitatea pe
langa Puterile Centrale. Noua situatie sud-estul
Europei  in special apropierea Austro-Ungariei de
Bulgaria si terea agresivitatii sale dupa 1908  cand a
anexat Bosnia si Hertegovina  s-a ant si asupra
situatiei romanilor din Transilvania. Cel din urma
eveniment
a intuat contradictiile in aceasta zona a
continentului  dat fiind si faptul ca entiile Rusiei
fata de stramtorile Bosfor si Dardanele au fost ignorate
la
Viena. asemenea  Bulgaria si-a manifestat dorinta de a
ingloba noi teritorii. De fapt  jaria dorea sa-si
sporeasca teritoriul pe seama Imperiului Otoman  prin
aceasta and in pericol statu-quo-u\ balcanic. in aceste
conditii s-a produs  in mod tat si greu de surprins de
cei neavizati  o detasare a tarii noastre de Puterile
trale. Ea s-a prelungit pana catre 1914  in pragul
conflagratiei mondiale.

--
You received this message because you are subscribed to
the
Google Groups "mongodb-user"
group.

For other MongoDB technical support options, see: https://docs.mongodb.com/manual/support/
---
You received this message because you are subscribed to
the
Google Groups "mongodb-user" group.
To unsubscribe from this group and stop receiving emails
from it, send an email to mongodb-user+***@googlegroups.com.
To post to this group, send email to mongodb-***@googlegroups.com.
Visit this group at
https://groups.google.com/group/mongodb-user.
To view this discussion on the web visit
https://groups.google.com/d/msgid/mongodb-user/1254037117.5756327.1481845448907%40mail.yahoo.com.
For more options, visit
https://groups.google.com/d/optout.rimii
ani ai secolului XX au marcat si deschiderea artei
romanesti catre universul de idei si forme ale curentului
modernist. Opera lui Constantin Brancusi  degajand o
viziune stilizata a volumelor  a fost  pentru
inceput  primita cu reticenta de publicul format si
educat artistic in spiritul curentului academismului. Se
afirma nume noi ca: A. Verona  N. Vermont  C.
Cutescu-Storck  Gh. Petrascu  Th. Pallady. in
sculptura  Ion Georgescusi stefan Valbudea preiau
stafeta de la dascalul lor  Carol Storck  pentru a
o preda unei
generatii   mai   tinere:   C.   Brancusi 
  D.   Paciurea    Fritz 
Storck.   Activitatea

--
You received this message because you are subscribed to the
Google Groups "mongodb-user"
group.

For other MongoDB technical support options, see: https://docs.mongodb.com/manual/support/
---
You received this message because you are subscribed to the
Google Groups "mongodb-user" group.
To unsubscribe from this group and stop receiving emails
from it, send an email to mongodb-user+***@googlegroups.com.
To post to this group, send email to mongodb-***@googlegroups.com.
Visit this group at
https://groups.google.com/group/mongodb-user.
To view this discussion on the web visit
https://groups.google.com/d/msgid/mongodb-user/1587706857.6050716.1481882385190%40mail.yahoo.com.
For more options, visit
https://groups.google.com/d/optout.usiei. Raspunsul echivoc al epitropului l-ar fi infuriat rostind cuvinte de cajn!J'
--
You received this message because you are subscribed to the Google Groups "mongodb-user"
group.

For other MongoDB technical support options, see: https://docs.mongodb.com/manual/support/
---
You received this message because you are subscribed to the Google Groups "mongodb-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mongodb-user+***@googlegroups.com.
To post to this group, send email to mongodb-***@googlegroups.com.
Visit this group at https://groups.google.com/group/mongodb-user.
To view this discussion on the web visit https://groups.google.com/d/msgid/mongodb-user/293029967.6271274.1481901200022%40mail.yahoo.com.
For more options, visit https://groups.google.com/d/optout.
Continue reading on narkive:
Loading...