Skip to content

Commit c1c86b2

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 1ce484b commit c1c86b2

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
@@ -153,6 +153,35 @@ When ``MongoClient.close()`` is called by any thread, the driver
153153
closes all idle sockets and closes all sockets that are in
154154
use as they are returned to the pool.
155155

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

@@ -229,7 +258,7 @@ For example, the following methods throws an exception during encoding:
229258
public String setField(String x);
230259

231260
How do I fix: "org.bson.codecs.configuration.CodecConfigurationException: Can't find a codec for class X."?
232-
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
261+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
233262

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

0 commit comments

Comments
 (0)