<!-- 
RSS generated by JIRA (9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66) at Wed Feb 07 21:18:43 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-3674] _mongoc_handshake_build_doc_with_application core dumps with strlen call</title>
                <link>https://jira.mongodb.org/browse/CDRIVER-3674</link>
                <project id="10030" key="CDRIVER">C Driver</project>
                    <description>&lt;p&gt;Hi,&lt;/p&gt;

&lt;p&gt;i migrated to 1.16.2 (with MongoDB 3.2) from very very old 1.0.2 release (was MongoDB 2.6). Im using driver for years with the simple setup, so i completed migration with no changes in mongoc snippets at all. The build is compiled from the sources with cmake / gcc, with no additional cmake options.&lt;/p&gt;

&lt;p&gt;And as far as i run new build ive got my application core dump.&lt;/p&gt;

&lt;p&gt;it is when i call&#160;mongoc_collection_remove() or&#160;mongoc_collection_insert() and this does not always happens.&#160;With the same query it may dumped or may not, and crashes about once out of ten times.&lt;/p&gt;

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

&lt;p&gt;gdb trace here&lt;/p&gt;

&lt;p&gt;#0 strlen () at /usr/src/lib/libc/arch/amd64/string/strlen.S:125&lt;br/&gt;
#1 0x000001ccf0f4db22 in _mongoc_handshake_build_doc_with_application () from /usr/local/lib/libmongoc-1.0.so.0.0&lt;br/&gt;
#2 0x000001ccf0f816d1 in _build_ismaster_with_handshake () from /usr/local/lib/libmongoc-1.0.so.0.0&lt;br/&gt;
#3 0x000001ccf0f815af in _mongoc_topology_scanner_get_ismaster () from /usr/local/lib/libmongoc-1.0.so.0.0&lt;br/&gt;
#4 0x000001ccf0f82c08 in _begin_ismaster_cmd () from /usr/local/lib/libmongoc-1.0.so.0.0&lt;br/&gt;
#5 0x000001ccf0f82a7d in mongoc_topology_scanner_node_setup_tcp () from /usr/local/lib/libmongoc-1.0.so.0.0&lt;br/&gt;
#6 0x000001ccf0f82203 in mongoc_topology_scanner_node_setup () from /usr/local/lib/libmongoc-1.0.so.0.0&lt;br/&gt;
#7 0x000001ccf0f8336b in mongoc_topology_scanner_start () from /usr/local/lib/libmongoc-1.0.so.0.0&lt;br/&gt;
#8 0x000001ccf0f7b2dc in mongoc_topology_scan_once () from /usr/local/lib/libmongoc-1.0.so.0.0&lt;br/&gt;
#9 0x000001ccf0f7b244 in _mongoc_topology_do_blocking_scan () from /usr/local/lib/libmongoc-1.0.so.0.0&lt;br/&gt;
#10 0x000001ccf0f7b88c in mongoc_topology_select_server_id () from /usr/local/lib/libmongoc-1.0.so.0.0&lt;br/&gt;
#11 0x000001ccf0f290c0 in _mongoc_cluster_select_server_id () from /usr/local/lib/libmongoc-1.0.so.0.0&lt;br/&gt;
#12 0x000001ccf0f24f14 in _mongoc_cluster_stream_for_optype () from /usr/local/lib/libmongoc-1.0.so.0.0&lt;br/&gt;
#13 0x000001ccf0f25029 in mongoc_cluster_stream_for_writes () from /usr/local/lib/libmongoc-1.0.so.0.0&lt;br/&gt;
#14 0x000001ccf0f2e2ad in _mongoc_collection_write_command_execute () from /usr/local/lib/libmongoc-1.0.so.0.0&lt;br/&gt;
#15 0x000001ccf0f30785 in mongoc_collection_remove () from /usr/local/lib/libmongoc-1.0.so.0.0&lt;/p&gt;

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

&lt;p&gt;gcc -v&lt;br/&gt;
Reading specs from /usr/lib/gcc-lib/amd64-unknown-openbsd6.6/4.2.1/specs&lt;br/&gt;
Target: amd64-unknown-openbsd6.6&lt;br/&gt;
Configured with: OpenBSD/amd64 system compiler&lt;br/&gt;
Thread model: posix&lt;br/&gt;
gcc version 4.2.1 20070719&lt;/p&gt;

&lt;p&gt;CVS to this strlen&lt;/p&gt;

&lt;p&gt;&lt;a href=&quot;https://cvsweb.openbsd.org/cgi-bin/cvsweb/~checkout~/src/lib/libc/arch/amd64/string/strlen.S?rev=1.8&amp;amp;content-type=text/plain&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;https://cvsweb.openbsd.org/cgi-bin/cvsweb/~checkout~/src/lib/libc/arch/amd64/string/strlen.S?rev=1.8&amp;amp;content-type=text/plain&lt;/a&gt;&lt;/p&gt;

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

&lt;p&gt;PS: im new here, so i could missing something in rules. youre welcome to ask me.&lt;/p&gt;</description>
                <environment>Openbsd 6.6. driver 1.16.2</environment>
        <key id="1352499">CDRIVER-3674</key>
            <summary>_mongoc_handshake_build_doc_with_application core dumps with strlen call</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="13202">Works as Designed</resolution>
                                        <assignee username="kevin.albertson@mongodb.com">Kevin Albertson</assignee>
                                    <reporter username="asuwish.def@gmail.com">Sergey Baranov</reporter>
                        <labels>
                    </labels>
                <created>Fri, 15 May 2020 13:26:22 +0000</created>
                <updated>Fri, 27 Oct 2023 13:14:09 +0000</updated>
                            <resolved>Tue, 26 May 2020 18:39:30 +0000</resolved>
                                    <version>1.14.0</version>
                    <version>1.15.0</version>
                    <version>1.16.2</version>
                    <version>1.17.0-beta</version>
                                                    <component>bsd</component>
                    <component>libmongoc</component>
                                        <votes>0</votes>
                                    <watches>3</watches>
                                                                                                                <comments>
                            <comment id="3111511" author="JIRAUSER1252109" created="Tue, 26 May 2020 21:12:26 +0000"  >&lt;p&gt;thank you much for investigation and focused support.&lt;/p&gt;</comment>
                            <comment id="3107621" author="kevin.albertson" created="Tue, 26 May 2020 18:39:30 +0000"  >&lt;p&gt;Great, glad to hear it is working now!&lt;/p&gt;</comment>
                            <comment id="3107607" author="JIRAUSER1252109" created="Tue, 26 May 2020 18:33:25 +0000"  >&lt;p&gt;i think you are right!&lt;/p&gt;

&lt;p&gt;i made code review and noticed that one contributor commited new function with mongoc_init/mongoc_cleanup calls, and it called few steps before my mongoc routine, whitch contains these too. I knew that init and cleanup must be once application starts and terminates, but since the new function actually do nothing with the database yet (its &lt;br/&gt;
for future use), i cannot catch it with my debugs. But it seems it was leading sometimes to incorrect mongoc states.&lt;/p&gt;

&lt;p&gt;I just moved mongoc_init/cleanup calls outside of that local fuctions and i get 100+ application cycles with zero segfaults.&lt;/p&gt;

&lt;p&gt;So i would ask you to close the issue.&lt;/p&gt;</comment>
                            <comment id="3106659" author="kevin.albertson" created="Tue, 26 May 2020 13:02:28 +0000"  >&lt;p&gt;Thanks for the response.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;And it seems im using a bit old mongoc API (it is exactly the same i was using in mongoc 1.0.2), and as i know its not deprecated or so, but i thought may be to re-write it with newest API. How you think would it change something in the mongoc calls chain? It seems not the case.&lt;/p&gt;&lt;/blockquote&gt;

&lt;p&gt;That&apos;s true. &lt;tt&gt;mongoc_collection_insert&lt;/tt&gt; is &lt;a href=&quot;http://mongoc.org/libmongoc/current/mongoc_collection_insert.html&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;documented&lt;/a&gt; as being superseded by &lt;tt&gt;mongoc_collection_insert_one&lt;/tt&gt; and &lt;tt&gt;mongoc_collection_insert_many&lt;/tt&gt;. But mongoc_collection_insert is a light wrapper around mongoc_collection_insert_one. Though it&apos;s probably best to change those calls to the newer API, that should not change behavior.&lt;/p&gt;

&lt;p&gt;One other guess... is it possible &lt;tt&gt;mongoc_cleanup&lt;/tt&gt; is called before the application terminates? The snippets do not include those calls, but perhaps it is elsewhere. &lt;tt&gt;mongoc_cleanup&lt;/tt&gt; cleans up all global state. If it was called (from any thread) that would invalidate libmongoc&apos;s global state (including the handshake).&lt;/p&gt;</comment>
                            <comment id="3106477" author="JIRAUSER1252109" created="Tue, 26 May 2020 09:33:14 +0000"  >&lt;p&gt;At the first glance, it seems that simple looped snippets arent going with segfault for me...&lt;br/&gt;
Im not sure how thats linking to the issue, but its good signal to investigate my original process a bit deeper.&lt;/p&gt;

&lt;p&gt;Kevin, lets hold this issue, i hope i will catch something new if the root cause leads to my code around.&lt;/p&gt;</comment>
                            <comment id="3106385" author="JIRAUSER1252109" created="Tue, 26 May 2020 07:41:35 +0000"  >&lt;p&gt;I do multiple threads, but threads do not work with mongoc ever (neither mongoc nor the data which i use with mongoc), all the mongoc operations are in parent thread only. Moreover, i thought there may be some kind of race condition when system is running multiple processes (multiple parent threads doing with mongoc and one of them segfaults), but single process had segfault too.&lt;/p&gt;

&lt;p&gt;i dont know, probably i should try to make simple program, which will loop my snippet to check will it crash or no. &lt;br/&gt;
And it seems im using a bit old mongoc API (it is exactly the same i was using in mongoc 1.0.2), and as i know its not deprecated or so, but i thought may be to re-write it with newest API. How you think would it change something in the mongoc calls chain? It seems not the case.&lt;/p&gt;

&lt;p&gt;No, i do not call `mongoc_handshake_data_append`.&lt;/p&gt;</comment>
                            <comment id="3106213" author="kevin.albertson" created="Mon, 25 May 2020 23:19:10 +0000"  >&lt;p&gt;Thank you for the snippets. Those seem reasonable to me. Modifying them slightly and running them on my end did not reproduce the same segfault. So I may need more information to diagnose.&lt;/p&gt;

&lt;p&gt;Given that this does not reproduce consistently, is your application creating multiple threads? Looking through mongoc-handshake.c, I do see a minor data race if multiple single-threaded &lt;tt&gt;mongoc_client_t&lt;/tt&gt;&#160;were to be running in separate threads (as opposed to multiple &lt;tt&gt;mongoc_client_t&lt;/tt&gt;&#160;obtained from a &lt;tt&gt;mongoc_client_pool_t&lt;/tt&gt;). Sure enough running an example creating 100 threads with single threaded &lt;tt&gt;mongoc_client_t&lt;/tt&gt;&#160;produces a warning from a thread-sanitizer:&lt;/p&gt;

&lt;p/&gt;
&lt;div id=&quot;syntaxplugin&quot; class=&quot;syntaxplugin&quot; style=&quot;border: 1px dashed #bbb; border-radius: 5px !important; overflow: auto; max-height: 30em;&quot;&gt;
&lt;table cellspacing=&quot;0&quot; cellpadding=&quot;0&quot; border=&quot;0&quot; width=&quot;100%&quot; style=&quot;font-size: 1em; line-height: 1.4em !important; font-weight: normal; font-style: normal; color: black;&quot;&gt;
		&lt;tbody &gt;
				&lt;tr id=&quot;syntaxplugin_code_and_gutter&quot;&gt;
						&lt;td  style=&quot; line-height: 1.4em !important; padding: 0em; vertical-align: top;&quot;&gt;
					&lt;pre style=&quot;font-size: 1em; margin: 0 10px;  margin-top: 10px;   width: auto; padding: 0;&quot;&gt;&lt;span style=&quot;color: black; font-family: &apos;Consolas&apos;, &apos;Bitstream Vera Sans Mono&apos;, &apos;Courier New&apos;, Courier, monospace !important;&quot;&gt;WARNING: ThreadSanitizer: data race (pid=31379)&lt;/span&gt;&lt;/pre&gt;
			&lt;/td&gt;
		&lt;/tr&gt;
				&lt;tr id=&quot;syntaxplugin_code_and_gutter&quot;&gt;
						&lt;td  style=&quot; line-height: 1.4em !important; padding: 0em; vertical-align: top;&quot;&gt;
					&lt;pre style=&quot;font-size: 1em; margin: 0 10px;   width: auto; padding: 0;&quot;&gt;&lt;span style=&quot;color: black; font-family: &apos;Consolas&apos;, &apos;Bitstream Vera Sans Mono&apos;, &apos;Courier New&apos;, Courier, monospace !important;&quot;&gt; Write of size 1 at 0x000104572128 by thread T1:&lt;/span&gt;&lt;/pre&gt;
			&lt;/td&gt;
		&lt;/tr&gt;
				&lt;tr id=&quot;syntaxplugin_code_and_gutter&quot;&gt;
						&lt;td  style=&quot; line-height: 1.4em !important; padding: 0em; vertical-align: top;&quot;&gt;
					&lt;pre style=&quot;font-size: 1em; margin: 0 10px;   width: auto; padding: 0;&quot;&gt;&lt;span style=&quot;color: black; font-family: &apos;Consolas&apos;, &apos;Bitstream Vera Sans Mono&apos;, &apos;Courier New&apos;, Courier, monospace !important;&quot;&gt; #0 _mongoc_handshake_freeze mongoc-handshake.c:565 (libmongoc-1.0.0.dylib:x86_64+0x6560b)&lt;/span&gt;&lt;/pre&gt;
			&lt;/td&gt;
		&lt;/tr&gt;
				&lt;tr id=&quot;syntaxplugin_code_and_gutter&quot;&gt;
						&lt;td  style=&quot; line-height: 1.4em !important; padding: 0em; vertical-align: top;&quot;&gt;
					&lt;pre style=&quot;font-size: 1em; margin: 0 10px;   width: auto; padding: 0;&quot;&gt;&lt;span style=&quot;color: black; font-family: &apos;Consolas&apos;, &apos;Bitstream Vera Sans Mono&apos;, &apos;Courier New&apos;, Courier, monospace !important;&quot;&gt; #1 _mongoc_topology_do_blocking_scan mongoc-topology.c:643 (libmongoc-1.0.0.dylib:x86_64+0xa3c68)&lt;/span&gt;&lt;/pre&gt;
			&lt;/td&gt;
		&lt;/tr&gt;
				&lt;tr id=&quot;syntaxplugin_code_and_gutter&quot;&gt;
						&lt;td  style=&quot; line-height: 1.4em !important; padding: 0em; vertical-align: top;&quot;&gt;
					&lt;pre style=&quot;font-size: 1em; margin: 0 10px;   width: auto; padding: 0;&quot;&gt;&lt;span style=&quot;color: black; font-family: &apos;Consolas&apos;, &apos;Bitstream Vera Sans Mono&apos;, &apos;Courier New&apos;, Courier, monospace !important;&quot;&gt; #2 mongoc_topology_select_server_id mongoc-topology.c:879 (libmongoc-1.0.0.dylib:x86_64+0xa46fa)&lt;/span&gt;&lt;/pre&gt;
			&lt;/td&gt;
		&lt;/tr&gt;
				&lt;tr id=&quot;syntaxplugin_code_and_gutter&quot;&gt;
						&lt;td  style=&quot; line-height: 1.4em !important; padding: 0em; vertical-align: top;&quot;&gt;
					&lt;pre style=&quot;font-size: 1em; margin: 0 10px;   width: auto; padding: 0;&quot;&gt;&lt;span style=&quot;color: black; font-family: &apos;Consolas&apos;, &apos;Bitstream Vera Sans Mono&apos;, &apos;Courier New&apos;, Courier, monospace !important;&quot;&gt; #3 _mongoc_cluster_select_server_id mongoc-cluster.c:2236 (libmongoc-1.0.0.dylib:x86_64+0x301ae)&lt;/span&gt;&lt;/pre&gt;
			&lt;/td&gt;
		&lt;/tr&gt;
				&lt;tr id=&quot;syntaxplugin_code_and_gutter&quot;&gt;
						&lt;td  style=&quot; line-height: 1.4em !important; padding: 0em; vertical-align: top;&quot;&gt;
					&lt;pre style=&quot;font-size: 1em; margin: 0 10px;   width: auto; padding: 0;&quot;&gt;&lt;span style=&quot;color: black; font-family: &apos;Consolas&apos;, &apos;Bitstream Vera Sans Mono&apos;, &apos;Courier New&apos;, Courier, monospace !important;&quot;&gt; #4 _mongoc_cluster_stream_for_optype mongoc-cluster.c:2282 (libmongoc-1.0.0.dylib:x86_64+0x2a5ac)&lt;/span&gt;&lt;/pre&gt;
			&lt;/td&gt;
		&lt;/tr&gt;
				&lt;tr id=&quot;syntaxplugin_code_and_gutter&quot;&gt;
						&lt;td  style=&quot; line-height: 1.4em !important; padding: 0em; vertical-align: top;&quot;&gt;
					&lt;pre style=&quot;font-size: 1em; margin: 0 10px;   width: auto; padding: 0;&quot;&gt;&lt;span style=&quot;color: black; font-family: &apos;Consolas&apos;, &apos;Bitstream Vera Sans Mono&apos;, &apos;Courier New&apos;, Courier, monospace !important;&quot;&gt; #5 mongoc_cluster_stream_for_writes mongoc-cluster.c:2368 (libmongoc-1.0.0.dylib:x86_64+0x2a6e7)&lt;/span&gt;&lt;/pre&gt;
			&lt;/td&gt;
		&lt;/tr&gt;
				&lt;tr id=&quot;syntaxplugin_code_and_gutter&quot;&gt;
						&lt;td  style=&quot; line-height: 1.4em !important; padding: 0em; vertical-align: top;&quot;&gt;
					&lt;pre style=&quot;font-size: 1em; margin: 0 10px;   width: auto; padding: 0;&quot;&gt;&lt;span style=&quot;color: black; font-family: &apos;Consolas&apos;, &apos;Bitstream Vera Sans Mono&apos;, &apos;Courier New&apos;, Courier, monospace !important;&quot;&gt; #6 _mongoc_collection_write_command_execute_idl mongoc-collection.c:94 (libmongoc-1.0.0.dylib:x86_64+0x383e6)&lt;/span&gt;&lt;/pre&gt;
			&lt;/td&gt;
		&lt;/tr&gt;
				&lt;tr id=&quot;syntaxplugin_code_and_gutter&quot;&gt;
						&lt;td  style=&quot; line-height: 1.4em !important; padding: 0em; vertical-align: top;&quot;&gt;
					&lt;pre style=&quot;font-size: 1em; margin: 0 10px;   width: auto; padding: 0;&quot;&gt;&lt;span style=&quot;color: black; font-family: &apos;Consolas&apos;, &apos;Bitstream Vera Sans Mono&apos;, &apos;Courier New&apos;, Courier, monospace !important;&quot;&gt; #7 mongoc_collection_insert_one mongoc-collection.c:1639 (libmongoc-1.0.0.dylib:x86_64+0x381c7)&lt;/span&gt;&lt;/pre&gt;
			&lt;/td&gt;
		&lt;/tr&gt;
				&lt;tr id=&quot;syntaxplugin_code_and_gutter&quot;&gt;
						&lt;td  style=&quot; line-height: 1.4em !important; padding: 0em; vertical-align: top;&quot;&gt;
					&lt;pre style=&quot;font-size: 1em; margin: 0 10px;   width: auto; padding: 0;&quot;&gt;&lt;span style=&quot;color: black; font-family: &apos;Consolas&apos;, &apos;Bitstream Vera Sans Mono&apos;, &apos;Courier New&apos;, Courier, monospace !important;&quot;&gt; #8 threadfn example-client.c:16 (example-client:x86_64+0x100003ab4)&lt;/span&gt;&lt;/pre&gt;
			&lt;/td&gt;
		&lt;/tr&gt;
				&lt;tr id=&quot;syntaxplugin_code_and_gutter&quot;&gt;
						&lt;td  style=&quot; line-height: 1.4em !important; padding: 0em; vertical-align: top;&quot;&gt;
					&lt;pre style=&quot;font-size: 1em; margin: 0 10px;   width: auto; padding: 0;&quot;&gt;&amp;nbsp;&lt;/pre&gt;
			&lt;/td&gt;
		&lt;/tr&gt;
				&lt;tr id=&quot;syntaxplugin_code_and_gutter&quot;&gt;
						&lt;td  style=&quot; line-height: 1.4em !important; padding: 0em; vertical-align: top;&quot;&gt;
					&lt;pre style=&quot;font-size: 1em; margin: 0 10px;   width: auto; padding: 0;&quot;&gt;&lt;span style=&quot;color: black; font-family: &apos;Consolas&apos;, &apos;Bitstream Vera Sans Mono&apos;, &apos;Courier New&apos;, Courier, monospace !important;&quot;&gt;Previous write of size 1 at 0x000104572128 by thread T2:&lt;/span&gt;&lt;/pre&gt;
			&lt;/td&gt;
		&lt;/tr&gt;
				&lt;tr id=&quot;syntaxplugin_code_and_gutter&quot;&gt;
						&lt;td  style=&quot; line-height: 1.4em !important; padding: 0em; vertical-align: top;&quot;&gt;
					&lt;pre style=&quot;font-size: 1em; margin: 0 10px;   width: auto; padding: 0;&quot;&gt;&lt;span style=&quot;color: black; font-family: &apos;Consolas&apos;, &apos;Bitstream Vera Sans Mono&apos;, &apos;Courier New&apos;, Courier, monospace !important;&quot;&gt; #0 _mongoc_handshake_freeze mongoc-handshake.c:565 (libmongoc-1.0.0.dylib:x86_64+0x6560b)&lt;/span&gt;&lt;/pre&gt;
			&lt;/td&gt;
		&lt;/tr&gt;
				&lt;tr id=&quot;syntaxplugin_code_and_gutter&quot;&gt;
						&lt;td  style=&quot; line-height: 1.4em !important; padding: 0em; vertical-align: top;&quot;&gt;
					&lt;pre style=&quot;font-size: 1em; margin: 0 10px;   width: auto; padding: 0;&quot;&gt;&lt;span style=&quot;color: black; font-family: &apos;Consolas&apos;, &apos;Bitstream Vera Sans Mono&apos;, &apos;Courier New&apos;, Courier, monospace !important;&quot;&gt; #1 _mongoc_topology_do_blocking_scan mongoc-topology.c:643 (libmongoc-1.0.0.dylib:x86_64+0xa3c68)&lt;/span&gt;&lt;/pre&gt;
			&lt;/td&gt;
		&lt;/tr&gt;
				&lt;tr id=&quot;syntaxplugin_code_and_gutter&quot;&gt;
						&lt;td  style=&quot; line-height: 1.4em !important; padding: 0em; vertical-align: top;&quot;&gt;
					&lt;pre style=&quot;font-size: 1em; margin: 0 10px;   width: auto; padding: 0;&quot;&gt;&lt;span style=&quot;color: black; font-family: &apos;Consolas&apos;, &apos;Bitstream Vera Sans Mono&apos;, &apos;Courier New&apos;, Courier, monospace !important;&quot;&gt; #2 mongoc_topology_select_server_id mongoc-topology.c:879 (libmongoc-1.0.0.dylib:x86_64+0xa46fa)&lt;/span&gt;&lt;/pre&gt;
			&lt;/td&gt;
		&lt;/tr&gt;
				&lt;tr id=&quot;syntaxplugin_code_and_gutter&quot;&gt;
						&lt;td  style=&quot; line-height: 1.4em !important; padding: 0em; vertical-align: top;&quot;&gt;
					&lt;pre style=&quot;font-size: 1em; margin: 0 10px;   width: auto; padding: 0;&quot;&gt;&lt;span style=&quot;color: black; font-family: &apos;Consolas&apos;, &apos;Bitstream Vera Sans Mono&apos;, &apos;Courier New&apos;, Courier, monospace !important;&quot;&gt; #3 _mongoc_cluster_select_server_id mongoc-cluster.c:2236 (libmongoc-1.0.0.dylib:x86_64+0x301ae)&lt;/span&gt;&lt;/pre&gt;
			&lt;/td&gt;
		&lt;/tr&gt;
				&lt;tr id=&quot;syntaxplugin_code_and_gutter&quot;&gt;
						&lt;td  style=&quot; line-height: 1.4em !important; padding: 0em; vertical-align: top;&quot;&gt;
					&lt;pre style=&quot;font-size: 1em; margin: 0 10px;   width: auto; padding: 0;&quot;&gt;&lt;span style=&quot;color: black; font-family: &apos;Consolas&apos;, &apos;Bitstream Vera Sans Mono&apos;, &apos;Courier New&apos;, Courier, monospace !important;&quot;&gt; #4 _mongoc_cluster_stream_for_optype mongoc-cluster.c:2282 (libmongoc-1.0.0.dylib:x86_64+0x2a5ac)&lt;/span&gt;&lt;/pre&gt;
			&lt;/td&gt;
		&lt;/tr&gt;
				&lt;tr id=&quot;syntaxplugin_code_and_gutter&quot;&gt;
						&lt;td  style=&quot; line-height: 1.4em !important; padding: 0em; vertical-align: top;&quot;&gt;
					&lt;pre style=&quot;font-size: 1em; margin: 0 10px;   width: auto; padding: 0;&quot;&gt;&lt;span style=&quot;color: black; font-family: &apos;Consolas&apos;, &apos;Bitstream Vera Sans Mono&apos;, &apos;Courier New&apos;, Courier, monospace !important;&quot;&gt; #5 mongoc_cluster_stream_for_writes mongoc-cluster.c:2368 (libmongoc-1.0.0.dylib:x86_64+0x2a6e7)&lt;/span&gt;&lt;/pre&gt;
			&lt;/td&gt;
		&lt;/tr&gt;
				&lt;tr id=&quot;syntaxplugin_code_and_gutter&quot;&gt;
						&lt;td  style=&quot; line-height: 1.4em !important; padding: 0em; vertical-align: top;&quot;&gt;
					&lt;pre style=&quot;font-size: 1em; margin: 0 10px;   width: auto; padding: 0;&quot;&gt;&lt;span style=&quot;color: black; font-family: &apos;Consolas&apos;, &apos;Bitstream Vera Sans Mono&apos;, &apos;Courier New&apos;, Courier, monospace !important;&quot;&gt; #6 _mongoc_collection_write_command_execute_idl mongoc-collection.c:94 (libmongoc-1.0.0.dylib:x86_64+0x383e6)&lt;/span&gt;&lt;/pre&gt;
			&lt;/td&gt;
		&lt;/tr&gt;
				&lt;tr id=&quot;syntaxplugin_code_and_gutter&quot;&gt;
						&lt;td  style=&quot; line-height: 1.4em !important; padding: 0em; vertical-align: top;&quot;&gt;
					&lt;pre style=&quot;font-size: 1em; margin: 0 10px;   width: auto; padding: 0;&quot;&gt;&lt;span style=&quot;color: black; font-family: &apos;Consolas&apos;, &apos;Bitstream Vera Sans Mono&apos;, &apos;Courier New&apos;, Courier, monospace !important;&quot;&gt; #7 mongoc_collection_insert_one mongoc-collection.c:1639 (libmongoc-1.0.0.dylib:x86_64+0x381c7)&lt;/span&gt;&lt;/pre&gt;
			&lt;/td&gt;
		&lt;/tr&gt;
				&lt;tr id=&quot;syntaxplugin_code_and_gutter&quot;&gt;
						&lt;td  style=&quot; line-height: 1.4em !important; padding: 0em; vertical-align: top;&quot;&gt;
					&lt;pre style=&quot;font-size: 1em; margin: 0 10px;   margin-bottom: 10px;  width: auto; padding: 0;&quot;&gt;&lt;span style=&quot;color: black; font-family: &apos;Consolas&apos;, &apos;Bitstream Vera Sans Mono&apos;, &apos;Courier New&apos;, Courier, monospace !important;&quot;&gt; #8 threadfn example-client.c:16 (example-client:x86_64+0x100003ab4)&lt;/span&gt;&lt;/pre&gt;
			&lt;/td&gt;
		&lt;/tr&gt;
			&lt;/tbody&gt;
&lt;/table&gt;
&lt;/div&gt;
&lt;p/&gt;

&lt;p&gt;That is due to a boolean being written by both threads. That seems worthwhile to fix in its own right, so I filed a separate ticket: &lt;a href=&quot;https://jira.mongodb.org/browse/CDRIVER-3685&quot; title=&quot;Single-threaded mongoc_client_t in separate threads may write to the global handshake &amp;quot;frozen&amp;quot; boolean&quot; class=&quot;issue-link&quot; data-issue-key=&quot;CDRIVER-3685&quot;&gt;CDRIVER-3685&lt;/a&gt;. But I don&apos;t see how that connects to the crash in strlen you are observing.&lt;/p&gt;


&lt;p&gt;Is it possible to include a compilable example? Including the the cmake/make commands and their output may additionally help diagnose.&lt;/p&gt;

&lt;p&gt;Additionally, I suspect the answer is &quot;no&quot;, but is any part of your code calling `mongoc_handshake_data_append`?&lt;/p&gt;</comment>
                            <comment id="3098782" author="JIRAUSER1252109" created="Thu, 21 May 2020 06:56:27 +0000"  >&lt;p&gt;And, as i said, these two may work fine most of times.&lt;/p&gt;</comment>
                            <comment id="3098779" author="JIRAUSER1252109" created="Thu, 21 May 2020 06:52:53 +0000"  >&lt;p&gt;Hi Kevin!&lt;/p&gt;

&lt;p&gt;Sure&lt;/p&gt;

&lt;p&gt;for example this two snippets get segfault&lt;/p&gt;

&lt;p&gt;	mongoc_client_t	*mongoclient = NULL;&lt;br/&gt;
	mongoc_collection_t	*mongocollection = NULL;&lt;br/&gt;
	const char	*collection_name = &quot;collection&quot;, *db_name = &quot;db&quot;;&lt;br/&gt;
	bson_oid_t	oid;&lt;br/&gt;
	bson_error_t	error;&lt;br/&gt;
	bson_t	*doc = NULL, *query = NULL, *opts = NULL;&lt;br/&gt;
	bson_iter_t	iter;&lt;br/&gt;
	const bson_t	*doc_current = NULL;&lt;br/&gt;
	mongoc_cursor_t	*cursor = NULL;&lt;/p&gt;

&lt;p&gt;	mongoc_init();&lt;br/&gt;
	mongoclient = mongoc_client_new(mongohost);&lt;br/&gt;
	mongocollection = mongoc_client_get_collection(mongoclient, db_name, collection_name);&lt;/p&gt;

&lt;p&gt;		if(mongoclient) {&lt;br/&gt;
			snprintf(cidstr, sizeof(cidstr), &quot;&lt;/p&gt;
{\&quot;key1\&quot;:\&quot;val1\&quot;,\&quot;key2\&quot;:\&quot;val2\&quot;,\&quot;key3\&quot;:\&quot;val3\&quot;,\&quot;data1\&quot;:\&quot;data\&quot;}
&lt;p&gt;&quot;);&lt;br/&gt;
			doc = bson_new();&lt;/p&gt;

&lt;p&gt;			if(!bson_init_from_json(doc, cidstr, -1, &amp;amp;error)) &lt;/p&gt;
{
				printf(&quot;BSON init error: %s\n&quot;, error.message);
			}
&lt;p&gt;			bson_oid_init(&amp;amp;oid, NULL);&lt;br/&gt;
			BSON_APPEND_OID(doc, &quot;_id&quot;, &amp;amp;oid);&lt;/p&gt;

&lt;p&gt;			if(options&amp;amp;F_INTERNAL) &lt;/p&gt;
{
				sstr = bson_as_json (doc, &amp;amp;len);
				printf(&quot;bson_as_json %s\n&quot;, sstr);
				bson_free (sstr);
			}

&lt;p&gt;//this ends with core dump&lt;br/&gt;
			if(!mongoc_collection_insert(mongocollection, MONGOC_INSERT_NONE, doc, NULL, &amp;amp;error)) &lt;/p&gt;
{
				printf(&quot;%s\n&quot;, error.message);
			}
&lt;p&gt;			bson_destroy(doc);&lt;/p&gt;

&lt;p&gt;		}&lt;/p&gt;

&lt;p&gt;#ONE MORE SNIPPET&lt;br/&gt;
		if(mongoclient) {&lt;br/&gt;
			query = bson_new();&lt;br/&gt;
			BSON_APPEND_UTF8(query, &quot;id&quot;, external_p-&amp;gt;id);&lt;br/&gt;
			opts = BCON_NEW (&quot;limit&quot;, BCON_INT64 (0), &quot;skip&quot;, BCON_INT64 (0));&lt;/p&gt;

&lt;p&gt;			cursor = mongoc_collection_find_with_opts(mongocollection, query, opts, NULL);&lt;/p&gt;

&lt;p&gt;//this ends with core dump&lt;br/&gt;
			while (mongoc_cursor_next(cursor, &amp;amp;doc_current)) {&lt;br/&gt;
				if(bson_iter_init(&amp;amp;iter, doc_current) &amp;amp;&amp;amp; bson_iter_find(&amp;amp;iter, &quot;data&quot;)) &lt;/p&gt;
{
					external_p-&amp;gt;data-&amp;gt;push(bson_iter_as_int64(&amp;amp;iter));
				}
&lt;p&gt;			}&lt;/p&gt;

&lt;p&gt;			mongoc_cursor_destroy(cursor);&lt;br/&gt;
			bson_destroy(opts);&lt;br/&gt;
			bson_destroy(query);&lt;br/&gt;
		}&lt;/p&gt;</comment>
                            <comment id="3098706" author="kevin.albertson" created="Thu, 21 May 2020 02:59:30 +0000"  >&lt;p&gt;Hello &lt;a href=&quot;https://jira.mongodb.org/secure/ViewProfile.jspa?name=asuwish.def%40gmail.com&quot; class=&quot;user-hover&quot; rel=&quot;asuwish.def@gmail.com&quot;&gt;asuwish.def@gmail.com&lt;/a&gt; , apologies for the delayed response.&lt;/p&gt;

&lt;p&gt;The handshake pointed to in the included stack trace is initialized globally upon calling &lt;tt&gt;mongoc_init&lt;/tt&gt;, which must be called at the start of the application (see &lt;a href=&quot;http://mongoc.org/libmongoc/current/mongoc_init.html&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;http://mongoc.org/libmongoc/current/mongoc_init.html&lt;/a&gt;). Is it possible there is a missing call to &lt;tt&gt;mongoc_init&lt;/tt&gt;?&lt;/p&gt;

&lt;p&gt;Though, that is just a speculation. If that does not resolve the issue, can you include any relevant snippet of your application code?&lt;/p&gt;
&lt;blockquote&gt;&lt;p&gt;mongoc_cursor_next() segmentation fault with the same tgdb trace as above.&lt;br/&gt;
 mongoc_collection_find_with_opts() works alltime with no issues&lt;/p&gt;&lt;/blockquote&gt;
&lt;p&gt;That is not unexpected based on the stack trace. The cursor returned by &lt;tt&gt;mongoc_collection_find_with_opts&lt;/tt&gt; is lazy. It will not send the find command until the first call to &lt;tt&gt;mongoc_cursor_next&lt;/tt&gt;.&lt;/p&gt;</comment>
                            <comment id="3097667" author="JIRAUSER1252109" created="Wed, 20 May 2020 16:39:51 +0000"  >&lt;p&gt;is someone here? &lt;img class=&quot;emoticon&quot; src=&quot;https://jira.mongodb.org/images/icons/emoticons/smile.png&quot; height=&quot;16&quot; width=&quot;16&quot; align=&quot;absmiddle&quot; alt=&quot;&quot; border=&quot;0&quot;/&gt;&lt;/p&gt;

&lt;p&gt;Just to update.&lt;br/&gt;
mongoc_cursor_next() segmentation fault with the same tgdb trace as above.&lt;br/&gt;
mongoc_collection_find_with_opts() works alltime with no issues&lt;/p&gt;</comment>
                            <comment id="3089696" author="JIRAUSER1252109" created="Fri, 15 May 2020 13:48:04 +0000"  >&lt;p&gt;gdb trace for insertion is the similar&lt;br/&gt;
#0  strlen () at /usr/src/lib/libc/arch/amd64/string/strlen.S:125&lt;br/&gt;
#1  0x0000013159d9d8c4 in _mongoc_handshake_build_doc_with_application () from /usr/local/lib/libmongoc-1.0.so.0.0&lt;br/&gt;
#2  0x0000013159dd16d1 in _build_ismaster_with_handshake () from /usr/local/lib/libmongoc-1.0.so.0.0&lt;br/&gt;
#3  0x0000013159dd15af in _mongoc_topology_scanner_get_ismaster () from /usr/local/lib/libmongoc-1.0.so.0.0&lt;br/&gt;
#4  0x0000013159dd2c08 in _begin_ismaster_cmd () from /usr/local/lib/libmongoc-1.0.so.0.0&lt;br/&gt;
#5  0x0000013159dd2a7d in mongoc_topology_scanner_node_setup_tcp () from /usr/local/lib/libmongoc-1.0.so.0.0&lt;br/&gt;
#6  0x0000013159dd2203 in mongoc_topology_scanner_node_setup () from /usr/local/lib/libmongoc-1.0.so.0.0&lt;br/&gt;
#7  0x0000013159dd336b in mongoc_topology_scanner_start () from /usr/local/lib/libmongoc-1.0.so.0.0&lt;br/&gt;
#8  0x0000013159dcb2dc in mongoc_topology_scan_once () from /usr/local/lib/libmongoc-1.0.so.0.0&lt;br/&gt;
#9  0x0000013159dcb244 in _mongoc_topology_do_blocking_scan () from /usr/local/lib/libmongoc-1.0.so.0.0&lt;br/&gt;
#10 0x0000013159dcb88c in mongoc_topology_select_server_id () from /usr/local/lib/libmongoc-1.0.so.0.0&lt;br/&gt;
#11 0x0000013159d790c0 in _mongoc_cluster_select_server_id () from /usr/local/lib/libmongoc-1.0.so.0.0&lt;br/&gt;
#12 0x0000013159d74f14 in _mongoc_cluster_stream_for_optype () from /usr/local/lib/libmongoc-1.0.so.0.0&lt;br/&gt;
#13 0x0000013159d75029 in mongoc_cluster_stream_for_writes () from /usr/local/lib/libmongoc-1.0.so.0.0&lt;br/&gt;
#14 0x0000013159d7e878 in _mongoc_collection_write_command_execute_idl () from /usr/local/lib/libmongoc-1.0.so.0.0&lt;br/&gt;
#15 0x0000013159d7e72f in mongoc_collection_insert_one () from /usr/local/lib/libmongoc-1.0.so.0.0&lt;br/&gt;
#16 0x0000013159d7e496 in mongoc_collection_insert () from /usr/local/lib/libmongoc-1.0.so.0.0&lt;/p&gt;</comment>
                            <comment id="3089689" author="JIRAUSER1252109" created="Fri, 15 May 2020 13:44:20 +0000"  >&lt;p&gt;insert query (i replaced the real data)&lt;/p&gt;

&lt;p&gt;{ &quot;key1&quot; : &quot;val1&quot;, &quot;key2&quot; : int_val1, &quot;key3&quot; : &quot;val3&quot;, &quot;key4&quot; : &lt;/p&gt;
{ &quot;key1_1&quot; : intval1_1, &quot;key2_2&quot; : &quot;val2_2&quot;, &quot;key3_3&quot; : &quot;val3_3&quot;, &quot;key4_4&quot; : int_val4_4, &quot;key5_5&quot; : &quot;val5_5&quot;, &quot;key6_6&quot; : [ &quot;val7_1&quot;, &quot;val7_2&quot;, int_val7_3, &quot;val7_4&quot;, &quot;val7_5&quot;, &quot;val7_6&quot;, &quot;val7_7&quot; ] }

&lt;p&gt;, &quot;_id&quot; : { &quot;$oid&quot; : &quot;5ebe90e36359dc3d01255953&quot; } }&lt;/p&gt;

&lt;p&gt;and remove query is simple&lt;/p&gt;

{ &quot;key1&quot; : &quot;val1&quot; }

&lt;p&gt;&#160;&lt;/p&gt;</comment>
                            <comment id="3089647" author="JIRAUSER1252109" created="Fri, 15 May 2020 13:30:27 +0000"  >&lt;p&gt;i also tried 1.15.0, 1.14.0, 1.17.0-beta with the same issue.&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|hx8osn:</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>