---
jvm 1 | java.lang.IllegalStateException: The connection may have
been used since this write, cannot obtain a result
jvm 1 | at com.mongodb.WriteResult.getLastError(WriteResult.java:98)
jvm 1 | at com.mongodb.WriteResult.getLastError(WriteResult.java:72)
---
Googling on this seems to show that the same connection was reused by
another thread before I could get the last error?
What needs to be done to avoid such errors?
Cheers,
Leif
If you plan to call getLastError after an update then you should
simply use WriteConcern.Safe in the write/update, and you will not
have this error.
I believe there was also a bug in an old version of the driver related
to this so you should probably upgrade to the latest if you aren't
using it.
This particular call had a WriteConcern.NONE. I understand that in
this case, the getLastError would not do anything. But this code was
shared and is called with different WriteConcern values.
We are are currently using the 2.6.3 Java driver.
We can go through and change our code so getLastError is never called
when WriteConcern was NONE. But I view this as a dangerous bug in the
API as it is not documented and does not happen reliably. In this
case, this system has already gone into production after going through
extensive testing without any problems. Would it be possible for you
modify the driver so getLastError does not try to access the
connection if the WriteConcern had a value which makes its use
illegal? Alternatively, it should always throw an
IllegalStateException. The second would probably cause problems for
existing users if they are doing what we were.
Thanks again,
Cheers,
Leif
On Thu, Jul 21, 2011 at 11:46 PM, Leif Mortenson
We have fixed this in our code for now, but I will have to make sure
that all of our developers know about this issue.
Cheers,
Leif
On Fri, Jul 22, 2011 at 12:50 PM, Scott Hernandez
As I said, this will only happen if the connection used on the update
has been used between that call and your next call. It means that you
have contention for you connections such that the thread didn't get it
back before some other thread used it (thread have affinity for the
same connection).
On Fri, Jul 22, 2011 at 12:23 AM, Leif Mortenson
I am concerned about this issue because of the very fact that its
behavior depends on whether or not other threads are active on the
system. That is inherently dangerous because simple test cases will
work perfectly while a larger live system will be much more likely to
encounter the problem.
We can work around this on our end now that it is understood. I don't
want to push endlessly other than to voice my concern that the current
API design is dangerous in the way I described. If it is possible to
fix without affecting performance then I think it would be a valuable
change to help improve the overall reliability of the software. As I
said, we did not discover this problem until our system had been live
for a couple weeks.
Cheers,
Leif
On Fri, Jul 22, 2011 at 1:33 PM, Scott Hernandez
db.RequestStart()
... // ops
db.RequestEnt()
http://www.mongodb.org/display/DOCS/Java+Driver+Concurrency Also, the
documentation for the DB class, and the method, also mention this.
It is important to understand how the driver works in order to design
your application and achieve the behavior you require.
I can understand that you this is a learning process and that some of
you assumptions, and tests, turned out to be different under load and
in production. I would suggest that you take this opportunity to
design more strenuous and concurrent tests. I'm sure this idea comes
as no surprise but I have found that doing this from the beginning
helps keep these kinds of surprises from coming up later in the game,
as they say.
Please let us know if there are any specific places where the
documentation could be updated, or changed, to make this more clear.
On Fri, Jul 22, 2011 at 1:00 AM, Leif Mortenson
I don't think we are doing anything else where concurrency is going to
be an issue
Thanks again for all your prompt help.
Cheers,
Leif
On Fri, Jul 22, 2011 at 2:41 PM, Scott Hernandez
Concurrency isn't something you use or don't use. It is inherent in
your application (runtime) at all times. It is good to be aware of it
since it can be an issue for the most simple of programs or functions.
On Mon, Jul 25, 2011 at 12:40 AM, Leif Mortenson