Skip to content
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

fix(NODE-3358): Command monitoring objects hold internal state references #2858

Conversation

W-A-James
Copy link
Contributor

@W-A-James W-A-James commented Jun 23, 2021

Modify extractCommand function used in apm event constructors to make deep copies of the command passed in

What changed?

  • lib/command_utils.js (cherry-picked from 299b969)
  • lib/core/connection/apm.js
  • lib/utils.js
  • test/functional/apm.test.js
  • test/unit/cmap/apm_events.test.js

@W-A-James W-A-James marked this pull request as ready for review June 23, 2021 15:39
@W-A-James W-A-James changed the title Node 3358/3.6/command monitoring objects hold internal state references fix(NODE-3358): Command monitoring objects hold internal state references Jun 23, 2021
@W-A-James W-A-James requested a review from dariakp June 23, 2021 19:48
@W-A-James W-A-James added the Primary Review In Review with primary reviewer, not yet ready for team's eyes label Jun 23, 2021
Copy link
Contributor

@dariakp dariakp left a comment

Choose a reason for hiding this comment

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

Just some clean up on the test, otherwise LGTM

expect(started[0].commandName).to.equal('insert');
expect(started[0].command.insert).to.equal('apm_test');
expect(succeeded).to.have.lengthOf(1);
return client.close();
Copy link
Contributor

Choose a reason for hiding this comment

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

sorry for not catching this in the 4.0 PR, but, since this belongs in the clean up, the ideal way to do it would be to have this in an afterEach block with the creation of the client in a beforeEach; to avoid refactoring too much, it's fine to wrap this in its own describe for that purpose

@W-A-James W-A-James requested a review from dariakp June 24, 2021 21:10
Copy link
Contributor

@dariakp dariakp left a comment

Choose a reason for hiding this comment

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

LGTM, thanks for the test clean up!

@dariakp dariakp added Team Review Needs review from team and removed Primary Review In Review with primary reviewer, not yet ready for team's eyes labels Jun 24, 2021
@dariakp dariakp requested review from nbbeeken, durran and emadum June 24, 2021 21:14
Copy link
Contributor

@emadum emadum left a comment

Choose a reason for hiding this comment

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

Mostly LGTM 👍 just had a few minor stylistic requests.

@@ -106,7 +108,7 @@ const extractCommand = command => {
extractedCommand = result;
}
} else {
extractedCommand = command.query || command;
extractedCommand = command.query ? deepCopy(command.query) : deepCopy(command);
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
extractedCommand = command.query ? deepCopy(command.query) : deepCopy(command);
extractedCommand = deepCopy(command.query || command);

I'd keep the more concise || syntax from the original code.

lib/utils.js Outdated
@@ -871,6 +871,85 @@ function emitWarningOnce(message) {
}
}

// Copied from https://github.com/mongodb/node-mongodb-native/blob/70cace8343bead2f3c1a6d0cf07e20a8c4a9f45f/src/utils.ts
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think these "copied from" comments are necessary.

describe('Internal state references', function() {
let client;

beforeEach(function(done) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Since newClient is synchronous, you can just pass a function() without a done argument and omit the the done() below.

});

afterEach(function(done) {
client.close(() => done());
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
client.close(() => done());
client.close(done);

@W-A-James W-A-James requested a review from emadum June 25, 2021 14:21
@dariakp dariakp merged commit 750760c into 3.6 Jun 25, 2021
@dariakp dariakp deleted the NODE-3358/3.6/Command-monitoring-objects-hold-internal-state-references branch June 25, 2021 18:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Team Review Needs review from team
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants