Skip to content

DOCSP-26368: FAQ entry for state should be open exception #416

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 27 additions & 1 deletion source/faq.txt
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,32 @@ When ``MongoClient.close()`` is called by any thread, the driver
closes all idle sockets and closes all sockets that are in
use as they are returned to the pool.

How do I prevent the "IllegalStateException: state should be: open" error?
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

You may encounter this exception if you call an operation on a ``MongoClient``
instance that closed its connections to MongoDB. The client's connections
can be closed for one of the following reasons:

- The ``close()`` method was called on that ``MongoClient`` instance prior
to the operation call.
- Another thread or process closed the connection. This can happen when
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't understand what the difference is between the first and second bullet. The only way to "close the connection" is to call the close method on the MongoClient. The difference only seems to be where the close is happening (how close/far it is from the code that is getting the exception, whether in the same thread or a different thread.

Also, it's not possible for another process to directly close a MongoClient. It would have to happen indirectly through communication through a socket, or some signal, etc.

Also, it may be the

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see. I assumed that this response was referring to an executor service operating on a pool of threads. Would you prefer I remove this list item to avoid any confusion? Is there any info you'd like to add? Thanks!

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, please remove. You could point out that often MongoClient instances are singletons that are accessible by multiple threads, and so the code which closes the MongoClient may be distant from the code receiving the exception, perhaps in another thread of execution.

the framework that your application uses to manage your MongoDB operations,
such as Spring Boot, closes connections.

To avoid this exception, do not call operations on ``MongoClient`` instance
that closed its connections.

If your application uses a framework to manage the ``MongoClient``,
check the documentation of the framework to locate the best practices for
managing the connection behavior.

.. seealso::

To learn more about accessing MongoDB from Spring Boot, see
`Spring Boot and MongoDB <https://www.mongodb.com/compatibility/spring-boot>`__.


POJOs
-----

Expand Down Expand Up @@ -224,7 +250,7 @@ For example, the following methods throws an exception during encoding:
public String setField(String x);

How do I fix: "org.bson.codecs.configuration.CodecConfigurationException: Can't find a codec for class X."?
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

This exception means you need to register a codec for the class since
there is none at the moment.
Expand Down