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-3810): delay timeout errors by one event loop tick #3180

Merged
merged 18 commits into from Apr 1, 2022

Conversation

nbbeeken
Copy link
Contributor

Description

What is changing?

Delay timeout errors from a socket by one event loop tick.

What is the motivation for this change?

In FAAS environments timers will expire between invocations but will only execute upon waking up. Node.js always runs timeouts first in the event loop, this means our monitoring socket will give us a timeout error before it reads the already pending hello response. By putting the timeout error logic inside another (small as possible) timeout callback it will enforce timeout errors to be handled on the next event loop iteration, giving the driver the opportunity to first read from the socket. If it is able to read, it will clear the timeout preventing the error from being raised to our monitoring logic. If nothing is ready pending to be read from the socket, the (small as possible) timeout will fire making the timeout error occur as usual.

Double check the following

  • Ran npm run check:lint script
  • Self-review completed using the steps outlined here
  • PR title follows the correct format: <type>(NODE-xxxx)<!>: <description>
  • Changes are covered by tests
  • New TODOs have a related JIRA ticket

@nbbeeken nbbeeken force-pushed the NODE-3810-delay-timeout-errors-pr-version branch from 74d3718 to eff2be2 Compare March 25, 2022 18:09
@nbbeeken nbbeeken added Primary Review In Review with primary reviewer, not yet ready for team's eyes and removed wip labels Mar 31, 2022
@nbbeeken nbbeeken marked this pull request as ready for review March 31, 2022 14:20
@nbbeeken nbbeeken requested a review from durran March 31, 2022 15:11
durran
durran previously approved these changes Mar 31, 2022
Copy link
Member

@durran durran left a comment

Choose a reason for hiding this comment

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

LGTM if we're ok with my one question. Nice work.

@durran durran added Team Review Needs review from team and removed Primary Review In Review with primary reviewer, not yet ready for team's eyes labels Mar 31, 2022
src/cmap/connection.ts Outdated Show resolved Hide resolved
test/unit/cmap/connection.test.ts Outdated Show resolved Hide resolved
test/unit/cmap/connection.test.ts Outdated Show resolved Hide resolved
test/unit/cmap/connection.test.ts Outdated Show resolved Hide resolved
test/unit/cmap/connection.test.ts Show resolved Hide resolved
test/unit/cmap/connection.test.ts Outdated Show resolved Hide resolved
test/unit/cmap/connection.test.ts Outdated Show resolved Hide resolved
@nbbeeken nbbeeken requested a review from dariakp March 31, 2022 19:21
@nbbeeken nbbeeken requested a review from durran March 31, 2022 19:22
test/unit/cmap/connection.test.ts Outdated Show resolved Hide resolved
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.

agree with Bailey's suggestion but otherwise LGTM

@durran durran merged commit 0ed7cbf into main Apr 1, 2022
@durran durran deleted the NODE-3810-delay-timeout-errors-pr-version branch April 1, 2022 15:38
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
4 participants