Skip to content

Commit 54c537b

Browse files
author
Chris Cho
committed
DOCSP-26368: FAQ entry for state should be open exception (#416)
* DOCSP-26368: FAQ entry for state should be open exception (cherry picked from commit 0e3f06f)
1 parent 2a2809b commit 54c537b

File tree

1 file changed

+30
-1
lines changed

1 file changed

+30
-1
lines changed

source/faq.txt

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,35 @@ When ``MongoClient.close()`` is called by any thread, the driver
148148
closes all idle sockets and closes all sockets that are in
149149
use as they are returned to the pool.
150150

151+
How do I prevent the "IllegalStateException: state should be: open" error?
152+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
153+
154+
You may encounter this exception if you call an operation on a ``MongoClient``
155+
instance that closed its connections to MongoDB. Once the ``close()`` method
156+
is called on the ``MongoClient``, any further operation calls on that instance
157+
throw this exception.
158+
159+
To avoid this exception, do not call operations on ``MongoClient`` instance
160+
after any code that calls ``close()`` on it.
161+
162+
.. tip::
163+
164+
The code that closes the ``MongoClient`` instance may be difficult to
165+
locate in certain cases. To locate potential sources of this exception,
166+
search for the following cases:
167+
168+
- Calls to ``close()`` on a ``MongoClient`` instance
169+
- Operation calls on a ``MongoClient`` instance that are outside the scope
170+
of the try-with-resources statement in which the ``MongoClient`` is
171+
declared
172+
173+
If your application uses a framework to manage the ``MongoClient``
174+
such as Spring Boot, check the documentation of the framework to locate the
175+
best practices for managing the connection behavior.
176+
177+
To learn more about accessing MongoDB from Spring Boot, see
178+
`Spring Boot and MongoDB <https://www.mongodb.com/compatibility/spring-boot>`__.
179+
151180
POJOs
152181
-----
153182

@@ -224,7 +253,7 @@ For example, the following methods throws an exception during encoding:
224253
public String setField(String x);
225254

226255
How do I fix: "org.bson.codecs.configuration.CodecConfigurationException: Can't find a codec for class X."?
227-
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
256+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
228257

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

0 commit comments

Comments
 (0)