<!-- 
RSS generated by JIRA (9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66) at Wed Feb 07 21:09:15 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-361] mongoc_collection_update hangs</title>
                <link>https://jira.mongodb.org/browse/CDRIVER-361</link>
                <project id="10030" key="CDRIVER">C Driver</project>
                    <description>&lt;p&gt;I have a about a dozen queries that the application runs.  Built, and tested on OS X 10.9.2.  All worked fine. Same mongo server, but compile and run on Solaris: SunOS staging-lock1 5.11 joyent_20131218T184706Z i86pc i386 i86pc Solaris, and one of the updates hangs forever.  &lt;/p&gt;

&lt;p&gt;The call stack is:&lt;/p&gt;

&lt;p&gt;(gdb) thread 13&lt;br/&gt;
&lt;span class=&quot;error&quot;&gt;&amp;#91;Switching to thread 13 (Thread 5 (LWP 5))&amp;#93;&lt;/span&gt;&lt;br/&gt;
#0  0xfffffd7fff225e1a in __so_sendmsg () from /lib/64/libc.so.1&lt;br/&gt;
(gdb) bt&lt;br/&gt;
#0  0xfffffd7fff225e1a in __so_sendmsg () from /lib/64/libc.so.1&lt;br/&gt;
#1  0xfffffd7fff211659 in _so_sendmsg () from /lib/64/libc.so.1&lt;br/&gt;
#2  0xfffffd7ffea4069e in __xnet_sendmsg () from /lib/64/libsocket.so.1&lt;br/&gt;
#3  0xfffffd7fe7c5fcf6 in _mongoc_socket_try_sendv () from /usr/local/lib/libmongoc-1.0.so.0&lt;br/&gt;
#4  0xfffffd7fe7c5fd9b in mongoc_socket_sendv () from /usr/local/lib/libmongoc-1.0.so.0&lt;br/&gt;
#5  0xfffffd7fe7c60840 in _mongoc_stream_socket_writev () from /usr/local/lib/libmongoc-1.0.so.0&lt;br/&gt;
#6  0xfffffd7fe7c541b5 in _mongoc_cluster_try_sendv () from /usr/local/lib/libmongoc-1.0.so.0&lt;br/&gt;
#7  0xfffffd7fe7c62830 in _mongoc_write_command_update_legacy () from /usr/local/lib/libmongoc-1.0.so.0&lt;br/&gt;
#8  0xfffffd7fe7c621c6 in _mongoc_write_command_execute () from /usr/local/lib/libmongoc-1.0.so.0&lt;br/&gt;
#9  0xfffffd7fe7c55b14 in mongoc_collection_update () from /usr/local/lib/libmongoc-1.0.so.0&lt;br/&gt;
#10 0x000000000040cc3f in tdata_store_set_message_status (self=0x4d4f48, message=0x4d7ca8) at tdata_store.c:242&lt;br/&gt;
#11 0x0000000000413639 in tmessage_endpoint_send_message_status_to_client (self=0x4c2e20, message=0x4d7ca8, message=0x4d16d0) at tmessage_endpoint.c:101&lt;br/&gt;
#12 0x0000000000413db1 in tmessage_endpoint_message_received (status=TMESSAGE_TRANSPORT_MESSAGE, sock_fd=25, connection=0x4d16d0, message=0x4d7ca8, context=0x4c2e20)&lt;br/&gt;
    at tmessage_endpoint.c:219&lt;br/&gt;
#13 0x0000000000414942 in tmessage_transport_fire_message_available (self=0x4eceb0, message=0x4d7ca8, connection=0x4d16d0) at tmessage_transport.c:221&lt;br/&gt;
#14 0x0000000000415002 in tmessage_transport_socket_callback_data (tsocket=0x4f2e50, connection=0x4d16d0, context=0x4eceb0) at tmessage_transport.c:405&lt;br/&gt;
#15 0x000000000041511c in tmessage_transport_socket_callback (tsocket=0x4f2e50, client_fd=25, connection=0x4d16d0, callback_type=TSOCKET_DATA, context=0x4eceb0)&lt;br/&gt;
    at tmessage_transport.c:453&lt;br/&gt;
#16 0x000000000040db0f in _TSocketServer_fireDataAvailableEvent (self=0x4f2e50, connection=0x4d16d0) at TSocket.c:205&lt;br/&gt;
#17 0x000000000040e07f in libev_read_cb (loop=0x4f3c50, watcher=0x4d16d0, revents=1) at TSocket.c:354&lt;br/&gt;
#18 0xfffffd7fe98f568d in ev_invoke_pending () from /opt/local/lib/ev/libev.so.4&lt;br/&gt;
#19 0xfffffd7fe98f84b1 in ev_run () from /opt/local/lib/ev/libev.so.4&lt;br/&gt;
#20 0x000000000040d6f4 in ev_loop (loop=0x4f3c50, flags=0) at ./include/libev/ev.h:826&lt;br/&gt;
#21 0x000000000040ea37 in _TSocketServer_Worker (ptr=0x4f2e50) at TSocket.c:614&lt;br/&gt;
#22 0xfffffd7fff21f46a in _thrp_setup () from /lib/64/libc.so.1&lt;br/&gt;
#23 0xfffffd7fff21f780 in ?? () from /lib/64/libc.so.1&lt;br/&gt;
#24 0x0000000000000000 in ?? ()&lt;/p&gt;


&lt;p&gt;The code in question is doing a simple upsert with the _id and one field with binary data in it.&lt;/p&gt;

&lt;p&gt;int&lt;br/&gt;
tdata_store_set_message_status(tdata_store_t *self, TPacketLocal_t *message)&lt;br/&gt;
{&lt;br/&gt;
	int rc = RETURN_UNINITIALIZED;&lt;/p&gt;

&lt;p&gt;	if(message &amp;amp;&amp;amp; message-&amp;gt;messagePtr &amp;amp;&amp;amp; message-&amp;gt;header.messageSize &amp;gt; 0) {&lt;br/&gt;
		char message_id&lt;span class=&quot;error&quot;&gt;&amp;#91;UUID_STR_LEN&amp;#93;&lt;/span&gt;;&lt;br/&gt;
		uuid_unparse(message-&amp;gt;header.messageId, message_id);&lt;/p&gt;

&lt;p&gt;		TTRACE_DATA_STORE(&quot;Setting last message status for message %s (%d bytes)&quot;, message_id, message-&amp;gt;header.messageSize);&lt;/p&gt;

&lt;p&gt;		// Update the messages table&lt;br/&gt;
		bson_t cond;&lt;/p&gt;

&lt;p&gt;		bson_init(&amp;amp;cond);&lt;br/&gt;
		BSON_APPEND_UUID(&amp;amp;cond, TDATA_STORE_ID_FIELD, message-&amp;gt;header.messageId);&lt;/p&gt;

&lt;p&gt;		bson_t update;&lt;br/&gt;
		bson_init(&amp;amp;update);&lt;br/&gt;
		bson_t child;&lt;br/&gt;
		bson_append_document_begin(&amp;amp;update, &quot;$set&quot;, -1, &amp;amp;child);&lt;br/&gt;
			BSON_APPEND_BINARY(&amp;amp;child, TDATA_STORE_message_STATUS_FIELD, BSON_SUBTYPE_BINARY, message-&amp;gt;messagePtr, message-&amp;gt;header.messageSize);&lt;br/&gt;
		bson_append_document_end(&amp;amp;update, &amp;amp;child);&lt;/p&gt;

&lt;p&gt;		mongoc_collection_t *collection = tdata_store_message_collection(self);/		&lt;br/&gt;
		bson_error_t error;&lt;/p&gt;

&lt;p&gt;		size_t length = 0;&lt;br/&gt;
		char * query_text = bson_as_json(&amp;amp;update, &amp;amp;length);&lt;/p&gt;

&lt;p&gt;		size_t cond_length = 0;&lt;br/&gt;
		char * cond_text = bson_as_json(&amp;amp;cond, &amp;amp;cond_length);&lt;/p&gt;

&lt;p&gt;		TTRACE_DATA_STORE(&quot;Updating collection...&quot;);&lt;br/&gt;
		TTRACE_DATA_STORE(&quot;QUERY: %s UPDATE: %s&quot;, cond_text, query_text);&lt;/p&gt;

&lt;p&gt;		// Update or insert the message&lt;/p&gt;

&lt;p&gt;---&amp;gt; HANGS		rc = mongoc_collection_update(collection,&lt;br/&gt;
								  MONGOC_UPDATE_UPSERT,&lt;br/&gt;
								  &amp;amp;cond,&lt;br/&gt;
								  &amp;amp;update,&lt;br/&gt;
								  NULL,&lt;br/&gt;
								  &amp;amp;error);						&lt;/p&gt;

&lt;p&gt;		if(!rc) &lt;/p&gt;
{
			TTRACE_DATA_STORE(&quot;Could not set message message status - %s&quot;, error.message);
			rc = RETURN_ERROR;
		}
&lt;p&gt; else &lt;/p&gt;
{
			TTRACE_DATA_STORE(&quot;Updated collection...&quot;);
			rc = RETURN_SUCCESS;
		}

&lt;p&gt;		rc = RETURN_SUCCESS;&lt;/p&gt;

&lt;p&gt;		bson_destroy(&amp;amp;update);&lt;br/&gt;
		bson_destroy(&amp;amp;child);&lt;br/&gt;
		bson_destroy(&amp;amp;cond);	&lt;/p&gt;

&lt;p&gt;		TTRACE_DATA_STORE(&quot;Set last status %d&quot;, rc);&lt;br/&gt;
	} else &lt;/p&gt;
{
		TTRACE_DATA_STORE(&quot;No message specified to set&quot;);
	}

&lt;p&gt;	return rc;&lt;br/&gt;
}&lt;/p&gt;

&lt;p&gt;And the two relevant trace lines are:&lt;/p&gt;

&lt;p&gt;&lt;span class=&quot;error&quot;&gt;&amp;#91;04-30-2014 16:32:02.147803&amp;#93;&lt;/span&gt; &lt;span class=&quot;error&quot;&gt;&amp;#91;TRACE&amp;#93;&lt;/span&gt; &lt;span class=&quot;error&quot;&gt;&amp;#91;DATA_STORE&amp;#93;&lt;/span&gt; Setting last message status for message 0bc6d80c-eb65-41f7-8b50-b657f5552043 (179 bytes) &lt;span class=&quot;error&quot;&gt;&amp;#91;tdata_store.c:tdata_store_set_message_status:213&amp;#93;&lt;/span&gt;&lt;br/&gt;
&lt;span class=&quot;error&quot;&gt;&amp;#91;04-30-2014 16:32:02.147889&amp;#93;&lt;/span&gt; &lt;span class=&quot;error&quot;&gt;&amp;#91;TRACE&amp;#93;&lt;/span&gt; &lt;span class=&quot;error&quot;&gt;&amp;#91;DATA_STORE&amp;#93;&lt;/span&gt; Updating collection... &lt;span class=&quot;error&quot;&gt;&amp;#91;tdata_store.c:tdata_store_set_message_status:238&amp;#93;&lt;/span&gt;&lt;br/&gt;
&lt;span class=&quot;error&quot;&gt;&amp;#91;04-30-2014 16:32:02.147909&amp;#93;&lt;/span&gt; &lt;span class=&quot;error&quot;&gt;&amp;#91;TRACE&amp;#93;&lt;/span&gt; &lt;span class=&quot;error&quot;&gt;&amp;#91;DATA_STORE&amp;#93;&lt;/span&gt; QUERY: &lt;/p&gt;
{ &quot;_id&quot; : &quot;0BC6D80C-EB65-41F7-8B50-B657F5552043&quot; }
&lt;p&gt; UPDATE: { &quot;$set&quot; : { &quot;status&quot; : &lt;/p&gt;
{ &quot;$type&quot; : &quot;00&quot;, &quot;$binary&quot; : &quot;lAHOlyhXOM4ZEV0CgqNzaWfaAEcwRQIhAMfrLai3DaOnq1B/cpHsCVmpX5dpxlHUOMuK+wEJu95NAiBwsSBbq4+ceFe85CpuyeVQwFPDlHYdlP6LZqbIN6vHLqNtc2faAFGUAc443kMHzhkRXQKDo2JhdGSobGNrU3RhdGUEpWxzdE9wg7FuZXRDb25lY3Rpb25TdGF0ZQOrbG9ja2VkU3RhdGUEpGRhdGXLiE1f3UG5EHE=&quot; }
&lt;p&gt; } } &lt;span class=&quot;error&quot;&gt;&amp;#91;tdata_store.c:tdata_store_set_message_status:239&amp;#93;&lt;/span&gt;&lt;/p&gt;</description>
                <environment>Solaris, hosted by Joyent.</environment>
        <key id="134184">CDRIVER-361</key>
            <summary>mongoc_collection_update hangs</summary>
                <type id="1" iconUrl="https://jira.mongodb.org/secure/viewavatar?size=xsmall&amp;avatarId=14703&amp;avatarType=issuetype">Bug</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="9">Done</resolution>
                                        <assignee username="christian.hergert@10gen.com">Christian Hergert</assignee>
                                    <reporter username="ekapke">Eric Kapke</reporter>
                        <labels>
                            <label>driver</label>
                    </labels>
                <created>Wed, 30 Apr 2014 16:43:30 +0000</created>
                <updated>Fri, 6 Jun 2014 15:48:50 +0000</updated>
                            <resolved>Fri, 6 Jun 2014 15:48:50 +0000</resolved>
                                    <version>0.92.2</version>
                    <version>0.94.0</version>
                    <version>0.94.2</version>
                                    <fixVersion>0.96.2</fixVersion>
                                                        <votes>0</votes>
                                    <watches>2</watches>
                                                                                                                <comments>
                            <comment id="611382" author="christian.hergert@10gen.com" created="Fri, 6 Jun 2014 15:48:50 +0000"  >&lt;p&gt;0.96.2 has been released with the various fixes. I&apos;m going to mark this issue as fixed. If you continue to have issues on 0.96.2, please do not hesitate to reopen the issue.&lt;/p&gt;

&lt;p&gt;&amp;#8211; Christian&lt;/p&gt;</comment>
                            <comment id="608421" author="christian.hergert@10gen.com" created="Wed, 4 Jun 2014 18:24:55 +0000"  >&lt;p&gt;I found another issue that could be related to this. It will go into 0.96.2.&lt;/p&gt;

&lt;p&gt;&lt;a href=&quot;https://github.com/mongodb/mongo-c-driver/commit/310609bf11c70fd50e503635363bb3525a4bd949&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;https://github.com/mongodb/mongo-c-driver/commit/310609bf11c70fd50e503635363bb3525a4bd949&lt;/a&gt;&lt;/p&gt;</comment>
                            <comment id="603121" author="christian.hergert@10gen.com" created="Fri, 30 May 2014 23:16:37 +0000"  >&lt;p&gt;Any chance I can have you run this test again using mongo-c-driver 0.96.0? There were some late fixes in a few areas that might get us moving in the right direction here. I&apos;d like to dive into this during the next cycle if it&apos;s still necessary.&lt;/p&gt;

&lt;p&gt;Also, you might consider running &lt;tt&gt;./configure&lt;/tt&gt; with &lt;tt&gt;--enable-tracing&lt;/tt&gt;.&lt;/p&gt;</comment>
                            <comment id="584049" author="christian.hergert@10gen.com" created="Wed, 14 May 2014 19:38:37 +0000"  >&lt;p&gt;Do you think you could add a test case for this to tests/test-mongoc-client.c and submit a pull request?&lt;/p&gt;</comment>
                            <comment id="584043" author="ekapke" created="Wed, 14 May 2014 19:35:43 +0000"  >&lt;p&gt;That&apos;s correct - I was purposely trying to use it from a single thread.  The main thread just initialized it - before the i/o thread was even created, then never touches the mongoc_client again.  I probably overlooked the fact that the init happened on the main thread.  It did work on OS X the way I had it, but just not on solaris. &lt;/p&gt;</comment>
                            <comment id="584034" author="christian.hergert@10gen.com" created="Wed, 14 May 2014 19:29:36 +0000"  >&lt;p&gt;Absolutely. The MongoDB driver is not thread-safe, it is thread-unaware. That means that you are responsible for providing the thread-safety.&lt;/p&gt;

&lt;p&gt;However, there is one place were the C driver currently deals with threads, and that is &lt;tt&gt;mongoc_client_pool_t&lt;/tt&gt;. That can be used in a thread-safe manner in situations such as web servers where you need to check a client out of the pool to handle a request. That uses pthread_mutex_t/pthread_cond_t internally (on UNIX-like systems).&lt;/p&gt;

&lt;p&gt;Now, if you created the client in one thread and passed it to another thread, meanwhile doing &lt;b&gt;nothing&lt;/b&gt; with it in the main thread, that is something we should look at.&lt;/p&gt;</comment>
                            <comment id="584021" author="ekapke" created="Wed, 14 May 2014 19:23:08 +0000"  >&lt;p&gt;I think the issue is not related to the query itself, rather a thread issue.&lt;/p&gt;

&lt;p&gt;1.  I made a tool that runs the same query (single thread) runs just fine.&lt;br/&gt;
2.  I refactored my code to use a queue with a dedicated thread where I the mongo client is initialized, and all mongo operations are run from.  Works just fine.&lt;br/&gt;
3.  In the stack trace above, the only difference seems to be the mongoc_client was initialized on the main thread, while db operations are run from a different I/O thread.  &lt;/p&gt;

&lt;p&gt;Perhaps its just user error?&lt;/p&gt;</comment>
                            <comment id="569082" author="christian.hergert@10gen.com" created="Thu, 1 May 2014 08:37:19 +0000"  >&lt;p&gt;Hi Eric, thanks for reporting this.&lt;/p&gt;

&lt;p&gt;Can you let me know what the version of the driver was used in the stack trace above? Based on your specified versions I assume you tried all of them?&lt;/p&gt;

&lt;p&gt;Do you have an idea of the size of upsert in bytes?&lt;/p&gt;

&lt;p&gt;Also, if you recompile with --enable-debug-symbols then we can get the number of iovec&apos;s that were being written in mongoc_socket_try_sendv() in the backtrace. That is interesting to me because I&apos;ve seen issues with scatter/gather IO on Solaris in the past with some previous iterations of the socket layer.&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|hrgh8n:</customfieldvalue>

                        </customfieldvalues>
                    </customfield>
                                                                <customfield id="customfield_10558" key="com.pyxis.greenhopper.jira:gh-global-rank">
                        <customfieldname>Rank (Obsolete)</customfieldname>
                        <customfieldvalues>
                            <customfieldvalue>9731</customfieldvalue>
                        </customfieldvalues>
                    </customfield>
                                                                                                                                                                                                                                                                    <customfield id="customfield_10557" key="com.pyxis.greenhopper.jira:gh-sprint">
                        <customfieldname>Sprint</customfieldname>
                        <customfieldvalues>
                                <customfieldvalue id="194">Sprint 3 -May 25 - June 13</customfieldvalue>

                        </customfieldvalues>
                    </customfield>
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            </customfields>
    </item>
</channel>
</rss>