Skip to content

GODRIVER-2872 Fix failing "TestClientSideEncryptionProse" test. #1359

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 2 commits into from
Aug 30, 2023

Conversation

qingyang-hu
Copy link
Collaborator

@qingyang-hu qingyang-hu commented Aug 18, 2023

GODRIVER-2872

Summary

Fix the failing "TestClientSideEncryptionProse" test by duplicating the memory passed to the C side.

Background & Motivation

The original comment was not accurate. The C side mongocrypt_binary_new_from_data() does a shallow copy of the passed array only, while the Golang slice which holds the memory may be freed or moved by GC.

Once a GC happens, for example, between C.mongocrypt_binary_new_from_data() and C.mongocrypt_ctx_encrypt_init(), the memory block pointed by C.mongocrypt_binary_t gets corrupted and resulted in sporadic "invalid BSON".

This PR proposes C.CBytes() to sync the lifecycle of the memory with the C code. Eventually, we can utilize runtime.Pinner (introduced in Go1.21.0) to avoid additional memory usage.

@qingyang-hu qingyang-hu marked this pull request as ready for review August 24, 2023 20:23
@qingyang-hu qingyang-hu requested a review from a team as a code owner August 24, 2023 20:23
@qingyang-hu qingyang-hu requested review from matthewdale and prestonvasquez and removed request for a team August 24, 2023 20:23
@github-actions
Copy link

API Change Report

No changes found!

Copy link
Collaborator

@matthewdale matthewdale left a comment

Choose a reason for hiding this comment

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

Great find! Looks good 👍

@qingyang-hu qingyang-hu merged commit 2f372fd into mongodb:master Aug 30, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants