[GODRIVER-2872] Fix failing "TestClientSideEncryptionProse" test Created: 16/Jun/23  Updated: 08/Nov/23  Resolved: 30/Aug/23

Status: Closed
Project: Go Driver
Component/s: Client Side Encryption
Affects Version/s: None
Fix Version/s: 1.12.2

Type: Bug Priority: Unknown
Reporter: Matt Dale Assignee: Qingyang Hu
Resolution: Fixed Votes: 0
Labels: greenerbuild
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Documentation Changes: Not Needed
Documentation Changes Summary:

1. What would you like to communicate to the user about this feature?
2. Would you like the user to see examples of the syntax and/or executable code and its output?
3. Which versions of the driver/connector does this apply to?


 Description   

The test

TestClientSideEncryptionProse/4._bson_size_limits

fails frequently with an error like

client_side_encryption_prose_test.go:470:
    	Error Trace:	mongo/integration/client_side_encryption_prose_test.go:470
    	            				mongo/integration/mongotest.go:263
    	Error:      	Expected nil, but got: mongo.MongocryptError{Code:1, Message:"invalid BSON"}
    	Test:       	TestClientSideEncryptionProse/4._bson_size_limits
    	Messages:   	InsertOne error: mongocrypt error 1: invalid BSON

Check out an example test failure here

Definition of done:

  • All TestClientSideEncryptionProse tests pass reliably on Evergreen CI.
  • Remove any skipped TestClientSideEncryptionProse tests tagged with this ticket.


 Comments   
Comment by Githook User [ 08/Nov/23 ]

Author:

{'name': 'Qingyang Hu', 'email': '103950869+qingyang-hu@users.noreply.github.com', 'username': 'qingyang-hu'}

Message: GODRIVER-2872 Duplicate slice passed to mongocrypt.newBinaryFromBytes(). (#1359)
Branch: release/1.12
https://github.com/mongodb/mongo-go-driver/commit/f7134aa2e58fb4e3df1405032f5c7ac5336609da

Comment by Qingyang Hu [ 30/Aug/23 ]

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".

Comment by Githook User [ 30/Aug/23 ]

Author:

{'name': 'Qingyang Hu', 'email': '103950869+qingyang-hu@users.noreply.github.com', 'username': 'qingyang-hu'}

Message: GODRIVER-2872 Duplicate slice passed to mongocrypt.newBinaryFromBytes(). (#1359)
Branch: master
https://github.com/mongodb/mongo-go-driver/commit/2f372fdae551b566fa65e6400e6bb52d745f9f2a

Generated at Thu Feb 08 08:39:33 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.