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

Conversation

ccho-mongodb
Copy link
Contributor

@ccho-mongodb ccho-mongodb commented Jun 29, 2023

Pull Request Info

PR Reviewing Guidelines

JIRA - https://jira.mongodb.org/browse/DOCSP-26368
Staging - https://docs-mongodbcom-staging.corp.mongodb.com/java/docsworker-xlarge/DOCSP-26368-FAQ-illegalstateexception/faq/#how-do-i-prevent-the--illegalstateexception--state-should-be--open--error-

Self-Review Checklist

  • Is this free of any warnings or errors in the RST?
  • Did you run a spell-check?
  • Did you run a grammar-check?
  • Are all the links working?

@ccho-mongodb ccho-mongodb marked this pull request as ready for review June 29, 2023 21:11
Copy link
Contributor

@rustagir rustagir left a comment

Choose a reason for hiding this comment

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

just a few things!

source/faq.txt Outdated
@@ -148,6 +148,26 @@ 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.

Why does the application throw "IllegalStateException: state should be: open"?
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggestion: make the question more oriented around the user

Suggested change
Why does the application throw "IllegalStateException: state should be: open"?
Why did I receive an "IllegalStateException: state should be: open" error?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks, I reworded since "receive" doesn't seem like a common action to describe exceptions.

source/faq.txt Outdated
Comment on lines 154 to 155
You may encounter this exception if you call an operation on a ``MongoClient``
instance that closed its connections to MongoDB. The connections could be
Copy link
Contributor

Choose a reason for hiding this comment

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

Question: Does the client close the connections or does the application close the connections? It could be helpful to clarify the wording here.

Suggested change
You may encounter this exception if you call an operation on a ``MongoClient``
instance that closed its connections to MongoDB. The connections could be
You may encounter this exception if you call an operation on a ``MongoClient``
instance with a closed connection to MongoDB. The connections could be

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'm not sure I understand the question since they both are responsible for the closing of the connection depending on perspective. An application must call the code to instruct the client to close. The client must close the connection when that method is called. Could you clarify what you meant?

Copy link
Contributor

Choose a reason for hiding this comment

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

I think I meant to ask whether there were times when a client closes a connection on its own, without the application containing/calling the close method. In any case, i think you can keep the wording as is

Copy link
Contributor Author

Choose a reason for hiding this comment

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

From what I understand, the client, which I'm assuming is MongoClient, can open and close connections based on load and network state (see How Does Connection Pooling Work in the Java Driver), but when you call an operation, whether a direct one such as ListDatabaseNames() or indirectly such as by calling find() on a MongoCollection, the MongoClient queues it up for the next available connection.

However, if you call close() on the instance, or perhaps another process signals for it to close its connections, it transitions into a state that is no longer "open" and does not accept any further operations.

source/faq.txt Outdated
Comment on lines 155 to 156
instance that closed its connections to MongoDB. The connections could be
closed due to one of the following conditions:
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
instance that closed its connections to MongoDB. The connections could be
closed due to one of the following conditions:
instance that closed its connections to MongoDB. The connections could be
closed for one of the following reasons:

source/faq.txt Outdated
instance that closed its connections to MongoDB. The connections could be
closed due to one of the following conditions:

- The ``close()`` method was called on that ``MongoClient`` instance
Copy link
Contributor

@rustagir rustagir Jun 30, 2023

Choose a reason for hiding this comment

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

Issue: end full sentence list items with periods

Suggested change
- The ``close()`` method was called on that ``MongoClient`` instance
- You previously called the ``close()`` method on the ``MongoClient`` instance.

source/faq.txt Outdated
closed due to one of the following conditions:

- The ``close()`` method was called on that ``MongoClient`` instance
- The ``MongoClient`` instance is out of scope
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
- The ``MongoClient`` instance is out of scope
- The ``MongoClient`` instance is out of scope.

source/faq.txt Outdated
Comment on lines 160 to 161
- The framework your application uses to manage your MongoDB operations, such
as Spring Boot, has closed the connection automatically.
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
- The framework your application uses to manage your MongoDB operations, such
as Spring Boot, has closed the connection automatically.
- The framework your application uses to manage your MongoDB operations, such
as Spring Boot, automatically closed the connection.

Also suggestion: link to something related to Spring Boot

Chris Cho added 2 commits July 19, 2023 14:41
Copy link
Contributor

@rustagir rustagir left a comment

Choose a reason for hiding this comment

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

lgtm!

source/faq.txt Outdated

- 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.

@ccho-mongodb ccho-mongodb requested a review from jyemin July 21, 2023 18:48
source/faq.txt Outdated
.. tip::

The code that closes the ``MongoClient`` instance may be difficult to
locate in certain cases. The ``MongoClient`` uses the singleton pattern,
Copy link
Collaborator

Choose a reason for hiding this comment

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

MongoClient doesn't use the singleton pattern itself. It's just that frameworks are often configured to manage these instances as singletons.

@ccho-mongodb ccho-mongodb requested a review from jyemin July 24, 2023 15:10
@ccho-mongodb ccho-mongodb merged commit 0e3f06f into mongodb:master Jul 24, 2023
@ccho-mongodb ccho-mongodb deleted the DOCSP-26368-FAQ-illegalstateexception branch July 24, 2023 22:05
ccho-mongodb pushed a commit that referenced this pull request Jul 24, 2023
* DOCSP-26368: FAQ entry for state should be open exception

(cherry picked from commit 0e3f06f)
ccho-mongodb pushed a commit that referenced this pull request Jul 24, 2023
* DOCSP-26368: FAQ entry for state should be open exception

(cherry picked from commit 0e3f06f)
ccho-mongodb pushed a commit that referenced this pull request Jul 24, 2023
* DOCSP-26368: FAQ entry for state should be open exception

(cherry picked from commit 0e3f06f)
ccho-mongodb pushed a commit that referenced this pull request Jul 24, 2023
* DOCSP-26368: FAQ entry for state should be open exception

(cherry picked from commit 0e3f06f)
ccho-mongodb pushed a commit that referenced this pull request Jul 24, 2023
* DOCSP-26368: FAQ entry for state should be open exception

(cherry picked from commit 0e3f06f)
ccho-mongodb pushed a commit that referenced this pull request Jul 24, 2023
* DOCSP-26368: FAQ entry for state should be open exception

(cherry picked from commit 0e3f06f)
ccho-mongodb pushed a commit that referenced this pull request Jul 24, 2023
* DOCSP-26368: FAQ entry for state should be open exception

(cherry picked from commit 0e3f06f)
ccho-mongodb pushed a commit that referenced this pull request Jul 24, 2023
* DOCSP-26368: FAQ entry for state should be open exception

(cherry picked from commit 0e3f06f)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants