[SERVER-36284] close() method on connections in the shell is broken with logical sessions Created: 25/Jul/18  Updated: 08/Jan/24

Status: Backlog
Project: Core Server
Component/s: Shell
Affects Version/s: None
Fix Version/s: None

Type: Bug Priority: Major - P3
Reporter: Jonathan Reams Assignee: Backlog - Server Tooling and Methods (STM) (Inactive)
Resolution: Unresolved Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Assigned Teams:
Server Tooling & Methods
Operating System: ALL
Steps To Reproduce:

Run this against a mongod with auth enabled and a user named "admin" with the password "admin"

var newConn = new Mongo();
newConn.getDB("admin").auth("admin", "admin");
newConn.close();

Although newConn is no longer usable, it won't actually be closed on the server side.

Sprint: Service Arch 2018-10-08, Service Arch 2018-10-22, Service Arch 2018-11-05, Service Arch 2018-11-19, Service Arch 2018-12-03, Service Arch 2018-12-17, Service Arch 2018-12-31, Service Arch 2019-01-14, Service Arch 2019-01-28, Service Arch 2019-02-11, Service Arch 2019-02-25, Service Arch 2019-03-11, Service Arch 2019-03-25
Participants:

 Description   

When logical sessions are implicitly created in the shell, they bump the ref-count of the client that created them, so that they can end the session on the same connection. The close() method on the Mongo connection works by resetting the shared_ptr<DBClientBase> that holds the underlying C++ client. Since the implicit session now holds a copy of that shared_ptr, close() basically does nothing.

There seem to be two options:

  • Have the Session object hold a weak_ptr to its DBClientBase, and lock/check the client before trying to end the session. The downside here is that the session might be finalized before the client and we'd leak the session on the server.
  • Have the client keep track of its default session and end it during its finalizer.


 Comments   
Comment by Steven Vannelli [ 10/May/22 ]

Moving this ticket to the Backlog and removing the "Backlog" fixVersion as per our latest policy for using fixVersions.

Comment by Mira Carey [ 25/Mar/19 ]

Passing this to STM with the understanding that users generally do not call close() on sockets, and that current behavior (holding sockets open if session objects exist which need to be ended) is required to avoid leaking sessions in the shell.

If you'd like this to work, I think there are reasonable approaches, but don't think this is something we strictly speaking need to handle from the "shell as product", rather than "shell as test harness" views of the shell

Comment by Gregory McKeon (Inactive) [ 01/Mar/19 ]

mira.carey@mongodb.com are we still sending this to STM?

Comment by Jonathan Reams [ 20/Aug/18 ]

I think the default sessions are the only sessions we actually care about here. I also think that if the session doesn't have a connection to end on, it should just throw. Extending the lifetime of network connections so that we can gracefully end logical sessions seems to defeat the purpose of logical sessions. If a user explicitly created a session, they'd already have to have logic to recreate the network connection in order to make use of the logical session. Otherwise, what's the point?

Generated at Thu Feb 08 04:42:38 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.