Skip to content

fix(NODE-6326): explicitly chain object lifetimes #42

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 3 commits into from
Sep 5, 2024

Conversation

addaleax
Copy link
Collaborator

Happy to get #41 merged first, then open this against a regular PR against the main branch with a NODE ticket and everything.


Description

What is changing?

The tests were previously encountering issues because creating an encryption/decryption context would not necessarily keep the parent mongocrypt_t alive, leading to intermittent crashes.

It appears that a similar issue has shown itself in the past w.r.t. KMS requests; the solution chosen there was to "chain" the object lifetimes through a JS property link on the wrapper objects for each C++ object.

This approach mostly works, but it is a bit brittle, because the JS engine and Node-API do not make strict guarantees about the order in which C++ wrapper objects are destroyed.

This commit tries to fully solve this problem by leaving it to the C++ wrapper objects to explicitly define lifetime relationships between them.

Is there new documentation needed for these changes?

No.

What is the motivation for this change?

The addon may crash. It currently only does so in tests, but it's not fundamentally impossible for this issue to show up in real-world usage.

Release Highlight

Fill in title or leave empty for no highlight

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

@baileympearson baileympearson changed the title fix: explicitly chain object lifetimes fix(NODE-6326): explicitly chain object lifetimes Aug 13, 2024
@baileympearson baileympearson changed the base branch from deps to main August 13, 2024 18:12
baileympearson and others added 3 commits August 14, 2024 10:01
The tests were previously encountering issues because creating an
encryption/decryption context would not necessarily keep the parent
`mongocrypt_t` alive, leading to intermittent crashes.

It appears that a similar issue has shown itself in the past w.r.t.
KMS requests; the solution chosen there was to "chain" the object
lifetimes through a JS property link on the wrapper objects for each
C++ object.

This approach mostly works, but it is a bit brittle, because the JS
engine and Node-API do not make strict guarantees about the order in
which C++ wrapper objects are destroyed.

This commit tries to fully solve this problem by leaving it to the C++
wrapper objects to explicitly define lifetime relationships
between them.
@baileympearson baileympearson force-pushed the explicit-lifetime-chaining branch from 68c9011 to d3d785b Compare August 14, 2024 16:01
@baileympearson
Copy link
Collaborator

(resolved merge conflicts from main)

@baileympearson
Copy link
Collaborator

I ran a patch against the driver using the changes here - everything looks good: https://spruce.mongodb.com/version/66d76a0742b67c0007b544a6/tasks?sorts=STATUS%3AASC%3BBASE_STATUS%3ADESC

(accidentally ran windows test too, ignore those)

@baileympearson baileympearson self-assigned this Sep 3, 2024
@baileympearson baileympearson added the Team Review Needs review from team label Sep 3, 2024
@baileympearson baileympearson merged commit ddb3fb8 into main Sep 5, 2024
31 checks passed
@baileympearson baileympearson deleted the explicit-lifetime-chaining branch September 5, 2024 15:57
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.

3 participants