<!-- 
RSS generated by JIRA (9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66) at Wed Feb 07 21:16:29 UTC 2024

It is possible to restrict the fields that are returned in this document by specifying the 'field' parameter in your request.
For example, to request only the issue key and summary append 'field=key&field=summary' to the URL of your request.
-->
<rss version="0.92" >
<channel>
    <title>MongoDB Jira</title>
    <link>https://jira.mongodb.org</link>
    <description>This file is an XML representation of an issue</description>
    <language>en-us</language>    <build-info>
        <version>9.7.1</version>
        <build-number>970001</build-number>
        <build-date>13-04-2023</build-date>
    </build-info>


<item>
            <title>[CDRIVER-2836] Issue with threading and incorrect data</title>
                <link>https://jira.mongodb.org/browse/CDRIVER-2836</link>
                <project id="10030" key="CDRIVER">C Driver</project>
                    <description>&lt;p&gt;Our server is multi-threaded and from what I can glime from the documentation it states that both mongodb c driver and bson is not thread safe.&lt;/p&gt;

&lt;p&gt;However I would have thought that if using the client pool I could get a client object for the thread that needs it so that the client object is thread safe and then getting a collection object from the client using&#160;mongoc_client_get_collection() and then a cursor object from the collection object using mongoc_collection_find_with_opts(), it should all be thread safe.&lt;/p&gt;

&lt;p&gt;All seems fine when performing requests across a single thread however if I start up a two or more threads I eventually get an issue where I am not seeing the correct data from the collection for that thread, I have created an assert that verifies that the data retrieved should be for that collection on a thread.&lt;/p&gt;

&lt;p&gt;Do I have to put a mutex lock/unlock combination around every bson and mongoc call?&lt;/p&gt;

&lt;p&gt;If that is the case the performance is going to be really bad.&lt;/p&gt;

&lt;p&gt;&#160;&lt;/p&gt;

&lt;p&gt;&#160;&lt;/p&gt;

&lt;p&gt;&#160;&lt;/p&gt;

&lt;p&gt;&#160;&lt;/p&gt;</description>
                <environment>Windows 10</environment>
        <key id="609591">CDRIVER-2836</key>
            <summary>Issue with threading and incorrect data</summary>
                <type id="3" iconUrl="https://jira.mongodb.org/secure/viewavatar?size=xsmall&amp;avatarId=14718&amp;avatarType=issuetype">Task</type>
                                            <priority id="3" iconUrl="https://jira.mongodb.org/images/icons/priorities/major.svg">Major - P3</priority>
                        <status id="6" iconUrl="https://jira.mongodb.org/images/icons/statuses/closed.png" description="The issue is considered finished, the resolution is correct. Issues which are closed can be reopened.">Closed</status>
                    <statusCategory id="3" key="done" colorName="success"/>
                                    <resolution id="13202">Works as Designed</resolution>
                                        <assignee username="-1">Unassigned</assignee>
                                    <reporter username="pcarruthers">Phillip Carruthers</reporter>
                        <labels>
                    </labels>
                <created>Tue, 25 Sep 2018 14:47:56 +0000</created>
                <updated>Fri, 27 Oct 2023 13:14:13 +0000</updated>
                            <resolved>Tue, 25 Sep 2018 15:24:39 +0000</resolved>
                                    <version>1.13.0</version>
                                                    <component>libbson</component>
                    <component>libmongoc</component>
                                        <votes>0</votes>
                                    <watches>1</watches>
                                                                                                                <comments>
                            <comment id="2014247" author="jesse" created="Tue, 25 Sep 2018 22:19:22 +0000"  >&lt;p&gt;Oh, I see the confusion. A bson_t or bson_iter_t is not thread-safe, so a single bson_t can&apos;t be used from multiple threads concurrently, nor can a single bson_iter_t be used from multiple threads concurrently. As long as you&apos;re not sharing a bson_t, bson_iter_t, or any other bson or mongoc struct from multiple threads concurrently you&apos;re fine.&lt;/p&gt;</comment>
                            <comment id="2014195" author="pcarruthers" created="Tue, 25 Sep 2018 21:39:04 +0000"  >&lt;p&gt;Hi&lt;br/&gt;
Ok so from what you are saying I should be able to use the client thread&lt;br/&gt;
pool in a multi-threaded environment and all the objects obtained from the&lt;br/&gt;
client object should be thread safe in that thread, which is what I would&lt;br/&gt;
expect.&lt;/p&gt;

&lt;p&gt;The bson doc says it is not thread safe so using the calls to marshal data&lt;br/&gt;
in and out of mongo document has to be protected by mutexes I believe, is&lt;br/&gt;
that the case?&lt;/p&gt;

&lt;p&gt;I am actually putting a mutex lock/unlock around the bson calls.&lt;/p&gt;

&lt;p&gt;However when I increase the number of active threads I hit an issue where&lt;br/&gt;
the data I have in the document is not for the collection on that thread.&lt;/p&gt;

&lt;p&gt;Regards&lt;br/&gt;
Phillip Carruthers&lt;br/&gt;
dbSpaces Limited&lt;/p&gt;

&lt;p&gt;This email and any attachments are intended only for the person or entity&lt;br/&gt;
for which it is addressed and may contain confidential material. If you&lt;br/&gt;
are not the addressee or have received this email in error, please inform&lt;br/&gt;
the sender immediately and delete it from your computer. In addition, if&lt;br/&gt;
you are not the addressee or have received this email in error, any&lt;br/&gt;
disclosure, copying, distribution or any action taken or omitted to be&lt;br/&gt;
taken in reliance&lt;br/&gt;
upon it is prohibited and may be unlawful.&lt;/p&gt;

&lt;p&gt;If this email has been transmitted outside the ordinary course of its&lt;br/&gt;
business, the company for which the sender works accepts no liability for&lt;br/&gt;
any loss or damage suffered by any person arising from any use of or&lt;br/&gt;
reliance on information contained in this email, and any opinion expressed&lt;br/&gt;
in this email is personal to the sender and may not reflect the opinion of&lt;br/&gt;
such company. Although the network operator makes every reasonable effort&lt;br/&gt;
to&lt;br/&gt;
keep its network free from viruses, neither the network operator nor the&lt;br/&gt;
sender or the company for which the sender works accepts any&lt;br/&gt;
responsibility for computer viruses transmitted through this email or any&lt;br/&gt;
attachments; it is your responsibility to virus scan this email and any&lt;br/&gt;
attachments. Any email reply to this address may be subject to&lt;br/&gt;
interception or monitoring for operational reasons or for lawful business&lt;br/&gt;
practices. &lt;/p&gt;






&lt;p&gt;On 25/09/2018, 20:21, &quot;A. Jesse Jiryu Davis (Jira)&quot; &amp;lt;jira@mongodb.org&amp;gt;&lt;/p&gt;
</comment>
                            <comment id="2013967" author="jesse" created="Tue, 25 Sep 2018 19:20:43 +0000"  >&lt;p&gt;Hi, can you please tell me what information would make the mongoc_client_pool_t tutorial more useful to you?&lt;/p&gt;

&lt;p&gt;Here&apos;s an answer to this question specifically:&lt;/p&gt;

&lt;p&gt;&amp;gt; However I would have thought that if using the client pool I could get a client object for the thread that needs it so that the client object is thread safe and then getting a collection object from the client using&#160;mongoc_client_get_collection() and then a cursor object from the collection object using mongoc_collection_find_with_opts(), it should all be thread safe.&lt;/p&gt;

&lt;p&gt;I think you&apos;re saying the right thing: only one thread at a time can use mongoc_client_t or any other C Driver object. Only mongoc_client_pool_t can be accessed from multiple threads concurrently. So, each thread checks out a client from the pool, uses that client, collection, and cursor in a single thread, and checks the client back into the pool. Other threads can run concurrently using different clients popped from the same pool. The tutorial provides an example of this pattern.&lt;/p&gt;</comment>
                            <comment id="2013891" author="pcarruthers" created="Tue, 25 Sep 2018 18:39:04 +0000"  >&lt;p&gt;Hi&lt;br/&gt;
That tutorial is of no use to anyone and I am surprised you closed my&lt;br/&gt;
question with that.&lt;br/&gt;
Have you actually looked at that tutorial?&lt;/p&gt;

&lt;p&gt;I would like a more informed response.&lt;/p&gt;

&lt;p&gt;Regards&lt;br/&gt;
Phillip Carruthers&lt;br/&gt;
dbSpaces Limited&lt;/p&gt;





&lt;p&gt;On 25/09/2018, 16:25, &quot;A. Jesse Jiryu Davis (Jira)&quot; &amp;lt;jira@mongodb.org&amp;gt;&lt;/p&gt;
</comment>
                            <comment id="2013551" author="jesse" created="Tue, 25 Sep 2018 15:24:39 +0000"  >&lt;p&gt;Hi! The answers are in the threading section of the tutorial:&lt;/p&gt;

&lt;p&gt;&#160;&lt;/p&gt;

&lt;p&gt;&lt;a href=&quot;http://mongoc.org/libmongoc/current/tutorial.html#threading&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;http://mongoc.org/libmongoc/current/tutorial.html#threading&lt;/a&gt;&lt;/p&gt;</comment>
                    </comments>
                    <attachments>
                    </attachments>
                <subtasks>
                    </subtasks>
                <customfields>
                                                                                                                                                                                                                                                                                                                                                                    <customfield id="customfield_15850" key="com.atlassian.jira.plugins.jira-development-integration-plugin:devsummary">
                        <customfieldname>Development</customfieldname>
                        <customfieldvalues>
                            
                        </customfieldvalues>
                    </customfield>
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            <customfield id="customfield_12550" key="com.pyxis.greenhopper.jira:gh-lexo-rank">
                        <customfieldname>Rank</customfieldname>
                        <customfieldvalues>
                            <customfieldvalue>2|htz807:</customfieldvalue>

                        </customfieldvalues>
                    </customfield>
                                                                <customfield id="customfield_10558" key="com.pyxis.greenhopper.jira:gh-global-rank">
                        <customfieldname>Rank (Obsolete)</customfieldname>
                        <customfieldvalues>
                            <customfieldvalue>9223372036854775807</customfieldvalue>
                        </customfieldvalues>
                    </customfield>
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            </customfields>
    </item>
</channel>
</rss>