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-5127): implement reject kmsRequest on server close #3964

Merged
merged 25 commits into from Jan 18, 2024

Conversation

alenakhineika
Copy link
Contributor

@alenakhineika alenakhineika commented Jan 12, 2024

Description

Handle onclose event in kmsRequest.

What is changing?

  • Adding onclose handler to the socket
  • Refactoring kmsRequest to async/await
Is there new documentation needed for these changes?

None

What is the motivation for this change?

NODE-5127
NODE-3959

Release Highlight

Fixed unresolved request issue in KMS requester

Internal to the field-level encryption machinery is a helper that opens a TLS socket to the KMS provider endpoint and submits a KMS request. The code neglected to add a 'close' event listener to the socket, which had the potential to improperly leave the promise pending indefinitely if no error was encountered.

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
    • Example: feat(NODE-1234)!: rewriting everything in coffeescript
  • Changes are covered by tests
  • New TODOs have a related JIRA ticket

@nbbeeken nbbeeken self-requested a review January 12, 2024 17:25
@nbbeeken nbbeeken self-assigned this Jan 12, 2024
@nbbeeken nbbeeken added the Primary Review In Review with primary reviewer, not yet ready for team's eyes label Jan 12, 2024
@alenakhineika alenakhineika changed the title fix(NODE-5127): Promise returned by libmongocrypt's StateMachine.kmsRequest never resolves when server closes connection without an error fix(NODE-5834): 6.x implement reject kmsRequest on server close Jan 15, 2024
@alenakhineika alenakhineika marked this pull request as ready for review January 15, 2024 15:03
src/client-side-encryption/state_machine.ts Show resolved Hide resolved
src/client-side-encryption/state_machine.ts Outdated Show resolved Hide resolved
src/client-side-encryption/state_machine.ts Outdated Show resolved Hide resolved
src/client-side-encryption/state_machine.ts Outdated Show resolved Hide resolved
src/client-side-encryption/state_machine.ts Outdated Show resolved Hide resolved
test/unit/client-side-encryption/state_machine.test.ts Outdated Show resolved Hide resolved
test/unit/client-side-encryption/state_machine.test.ts Outdated Show resolved Hide resolved
@nbbeeken nbbeeken changed the title fix(NODE-5834): 6.x implement reject kmsRequest on server close fix(NODE-5834): implement reject kmsRequest on server close Jan 17, 2024
@nbbeeken nbbeeken self-requested a review January 17, 2024 15:27
@nbbeeken nbbeeken added Team Review Needs review from team and removed Primary Review In Review with primary reviewer, not yet ready for team's eyes labels Jan 17, 2024
@alenakhineika alenakhineika changed the title fix(NODE-5834): implement reject kmsRequest on server close fix(NODE-5127): implement reject kmsRequest on server close Jan 18, 2024
.once('timeout', () => rejectOnNetSocketError(ontimeout()))
.once('error', err => rejectOnNetSocketError(onerror(err)))
.once('close', () => rejectOnNetSocketError(onclose()))
.once('connect', () => resolveOnNetSocketConnect());
Copy link
Contributor

Choose a reason for hiding this comment

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

[nit/question] Is there any reason, apart from style consistency, not to do this?

Suggested change
.once('connect', () => resolveOnNetSocketConnect());
.once('connect', resolveOnNetSocketConnect);

Copy link
Contributor

Choose a reason for hiding this comment

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

Here, no there isn't but I also would not change it.

Generally, you may want to be careful about passing a function directly into another API. Adding parameters to the listener would be considered a feature and not a breaking change, but our promise would resolve with whatever new parameters were added.

@nbbeeken nbbeeken merged commit 568e05f into main Jan 18, 2024
25 of 27 checks passed
@nbbeeken nbbeeken deleted the NODE-5127-reject-kms-request-onclose branch January 18, 2024 21:05
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
3 participants