fix(ReplSet): add HACK for "Maximum call stack size exceeded" in MongoClient topology

Closes #221
This commit is contained in:
nodkz
2019-10-22 21:31:39 +06:00
parent 14deb2c0fe
commit b25aa33e91
@@ -242,6 +242,17 @@ export default class MongoMemoryReplSet extends EventEmitter {
try {
const db = await conn.db(this.opts.replSet.dbName);
// MongoClient HACK which helps to avoid the following error:
// "RangeError: Maximum call stack size exceeded"
// in ./node_modules/mongodb/lib/core/sdam/topology_description.js:263:51
// Under the hood initiated server topology has type `RSGhost`
// and this server does not support session
// so for skipping the following code
// https://github.com/mongodb/node-mongodb-native/blob/dc70c2de7d3dae2617708c45a1ea695d131e15f3/lib/operations/execute_operation.js#L33-L39
// we just override shouldCheckForSessionSupport() method for current connection instance
(db as any).topology.shouldCheckForSessionSupport = () => false;
this.admin = db.admin();
const members = uris.map((uri, idx) => ({ _id: idx, host: getHost(uri) }));
const rsConfig = {