Skip to content

Conversation

@PavelSafronov
Copy link
Contributor

Description

Summary of Changes

Replace process.nextTick() with .queueMicrotask()

What is the motivation for this change?

This helps us reduce our runtime dependencies, as part of https://jira.mongodb.org/browse/NODE-6601

Double check the following

  • Lint is passing (npm run check:lint)
  • Self-review completed using the steps outlined here
  • PR title follows the correct format: type(NODE-xxxx)[!]: description
    • Example: feat(NODE-1234)!: rewriting everything in coffeescript
  • Changes are covered by tests
  • New TODOs have a related JIRA ticket

@PavelSafronov PavelSafronov reopened this Dec 3, 2025
addaleax
addaleax previously approved these changes Dec 3, 2025
@PavelSafronov PavelSafronov marked this pull request as ready for review December 5, 2025 19:59
@PavelSafronov PavelSafronov requested a review from a team as a code owner December 5, 2025 19:59
// This is a guarantee in node, unless you are performing a transaction (which is not being done in this test)
expect(new Set(events.map(ev => ev.command.lsid.id.toString('hex')))).to.have.lengthOf(1);
const uniqueSessionIds = new Set(events.map(ev => ev.command.lsid.id.toString('hex')));
expect(uniqueSessionIds).to.have.length.lessThanOrEqual(2);
Copy link
Member

@tadjik1 tadjik1 Dec 8, 2025

Choose a reason for hiding this comment

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

Can you please elaborate on this change?
Maybe some summary from the slack thread would be good for potential future investigations, wdyt?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Absolutely, adding information about the timing, as well as an example bulkWrite that would have broken the old version of this test.

Copy link
Member

@tadjik1 tadjik1 Dec 9, 2025

Choose a reason for hiding this comment

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

Thank you! Sorry for the ambiguity in my original request, I'm not sure if referring "previous version" in the code will help in the future because when you read the code you only see the present version. Maybe it would be enough to provide a context about bulkWrite creates its' own session which leads to the queue being processed in between of checkIn() and endSession(), that results in more than 1 session being created.
And this comment can be left in the PR so the diff is clear.

However, it's just a minor suggestion, I believe what you did works just fine.

Copy link
Contributor Author

@PavelSafronov PavelSafronov Dec 9, 2025

Choose a reason for hiding this comment

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

Yup, "previous version" doesn't make too much sense. Here's a different approach:

// We verify that the number of unique session IDs used is less than the number of operations.
//
// The current version of the driver + this test will result in 2 server session being used.
// 1. One server session is used for most operations
// 2. A second server session is created and used for the bulkWrite operation
//
// In the past, we used process.nextTick in our connection checkout logic, and it was possible for bulkWrite to complete its work
// fast enough that it would release its server session and result in only 1 server session being used.
// The current timing behavior results in 2 server sessions being used consistently.

@tadjik1 tadjik1 added the Primary Review In Review with primary reviewer, not yet ready for team's eyes label Dec 8, 2025
@tadjik1 tadjik1 self-assigned this Dec 8, 2025
@tadjik1 tadjik1 requested a review from a team December 8, 2025 10:30
@tadjik1 tadjik1 added the Team Review Needs review from team label Dec 9, 2025
Copy link
Member

@tadjik1 tadjik1 left a comment

Choose a reason for hiding this comment

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

Great work @PavelSafronov, thanks for the investigation around client sessions and queue processing!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Primary Review In Review with primary reviewer, not yet ready for team's eyes Team Review Needs review from team

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants