summaryrefslogtreecommitdiff
path: root/src/mongo/shell/mongo.js
diff options
context:
space:
mode:
authorKevin Pulo <kevin.pulo@mongodb.com>2018-08-09 04:00:41 +0000
committerKevin Pulo <kevin.pulo@mongodb.com>2018-09-03 06:18:37 +0000
commit23794c14b03bb272daad7a2b25eca0b80c03a31c (patch)
tree2c60ec7adb337f99cefe1af28d8b7f4eee3c9239 /src/mongo/shell/mongo.js
parent2704d7a89e64167fcff7356ada111b313146474e (diff)
downloadmongo-23794c14b03bb272daad7a2b25eca0b80c03a31c.tar.gz
SERVER-33606 fail to create logical session in shell connected to old servers
Also add --disableImplicitSessions shell cmdline arg.
Diffstat (limited to 'src/mongo/shell/mongo.js')
-rw-r--r--src/mongo/shell/mongo.js26
1 files changed, 23 insertions, 3 deletions
diff --git a/src/mongo/shell/mongo.js b/src/mongo/shell/mongo.js
index 635c77dbc67..416416d8b3f 100644
--- a/src/mongo/shell/mongo.js
+++ b/src/mongo/shell/mongo.js
@@ -263,6 +263,10 @@ connect = function(url, user, pass) {
}
}
+ if (_shouldUseImplicitSessions()) {
+ chatty("Implicit session: " + db.getSession());
+ }
+
// Implicit sessions should not be used when opening a connection. In particular, the buildInfo
// command is erroneously marked as requiring auth in MongoDB 3.6 and therefore fails if a
// logical session id is included in the request.
@@ -445,14 +449,30 @@ Mongo.prototype._getDefaultSession = function getDefaultSession() {
// a logical session id. These implicit sessions are intentionally not causally consistent. If
// implicit sessions have been globally disabled, a dummy session is used instead of a real one.
if (!this.hasOwnProperty("_defaultSession")) {
- this._defaultSession = _shouldUseImplicitSessions()
- ? this.startSession({causalConsistency: false})
- : new _DummyDriverSession(this);
+ if (_shouldUseImplicitSessions()) {
+ try {
+ this._defaultSession = this.startSession({causalConsistency: false});
+ } catch (e) {
+ if (e instanceof DriverSession.UnsupportedError) {
+ chatty("WARNING: No implicit session: " + e.message);
+ this._setDummyDefaultSession();
+ } else {
+ print("ERROR: Implicit session failed: " + e.message);
+ throw(e);
+ }
+ }
+ } else {
+ this._setDummyDefaultSession();
+ }
this._defaultSession._isExplicit = false;
}
return this._defaultSession;
};
+Mongo.prototype._setDummyDefaultSession = function setDummyDefaultSession() {
+ this._defaultSession = new _DummyDriverSession(this);
+};
+
Mongo.prototype.isCausalConsistency = function isCausalConsistency() {
if (!this.hasOwnProperty("_causalConsistency")) {
this._causalConsistency = false;