Skip to content

chore: capture more informative stack trace in session leak checker #2618

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
merged 2 commits into from
Nov 13, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 28 additions & 4 deletions test/tools/runner/plugins/session_leak_checker.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,14 @@ function getSessionLeakMetadata(currentTest) {
return (currentTest.metadata && currentTest.metadata.sessions) || {};
}

const kTrace = Symbol('trace');
function dumpSessionInfo(which, sessions) {
console.log(which);
console.warn(which);
sessions.forEach(session => {
console.log(` >> ${JSON.stringify(session.id)}`);
console.log(session.trace);
console.warn(` >> ${JSON.stringify(session.id)}`);
if (session[kTrace]) {
console.warn(session[kTrace]);
}
});
}

Expand All @@ -32,10 +35,31 @@ beforeEach('Session Leak Before Each - setup session tracking', function () {
return;
}

const _startSession = Topology.prototype.startSession;
sandbox.stub(Topology.prototype, 'startSession').callsFake(function () {
const session = _startSession.apply(this, arguments);
const stackTrace = new Error().stack;
const result = new Proxy(session, {
get: function (target, prop) {
if (prop === 'serverSession') {
const serverSession = target[prop];
if (serverSession[kTrace] == null) {
serverSession[kTrace] = stackTrace;
}

return serverSession;
}

return Reflect.get(...arguments);
}
});

return result;
});

const _acquire = ServerSessionPool.prototype.acquire;
sandbox.stub(ServerSessionPool.prototype, 'acquire').callsFake(function () {
const session = _acquire.apply(this, arguments);
session.trace = new Error().stack;
activeSessions.add(session);
return session;
});
Expand Down