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

clone returned byte slice in MarshalValue #1913

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

Ragnaroek
Copy link

No issue number yet, as for now unsure if this is intended behaviour or a bug.

Summary

This PR is not ready for merge. It's more to start a discussion around a behaviour I noticed while upgrading to v2 of the driver.

After the v2 driver upgrade unit-tests failed in our project. I took me a long time to find the issue, but I think the root cause is that 'MarshalValue' hands out byte slices that are potentially shared with the Buffers from the pool. This can lead to nasty race-conditions where the byte slices are modified in our test-setup.

I tried to reproduce the behaviour in a unit-test. But this somehow did not work. However the unit-test is a stripped down version of our unit-test in the project and should give you an idea how this leads to a problem with our tests. I can detail this further of course, if it helps to understand the issue.

The fix is easy in the end. If the byte slice is copied, the problem stops. I can do this on the usage side, but I think this shared behaviour of the returned bytes is very unintuitives and error prone in the edge-cases?

The PR proposes a copy of the bytes before returning them. Not sure that is something that is aligned with goals of the library function.

Background & Motivation

This PR fixes a very unintuitive and hard bug to find while "only" upgrading to v2 of the MongoDB driver. I assume other users of the library could also experience this and a proposal for a fix is up for a discussion.

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.

2 participants