<!-- 
RSS generated by JIRA (9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66) at Wed Feb 07 22:00:31 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>[CXX-840] Infinite wait in mongo 1.0.7 client if mongo::client::shutdown not explicitly called</title>
                <link>https://jira.mongodb.org/browse/CXX-840</link>
                <project id="11980" key="CXX">C++ Driver</project>
                    <description>&lt;p&gt;Hi All,&lt;/p&gt;

&lt;p&gt;Since updating from 2.x to 3.x, we&apos;ve experienced significant difficultly with the new client driver requiring the explicit calls to mongo::client::initialize and mongo::client::shutdown, with a fatal infinite wait in the replica set monitor watcher if mongo::client::shutdown is not called explicitly.&lt;/p&gt;

&lt;p&gt;We use Mongo in a shared library (dll) that is consumed by a number of clients, and in this scenario it&apos;s not straightforward to call mongo::client::shutdown from the parent executable.  When the executable dies and the mongo wrapper DLL unloads, the mongo client driver&apos;s threads are terminated before the destructor for the replica set monitor watcher is called.  When its destructor is called, it waits on a condition variable that will never be set, as the thread is already gone.&lt;/p&gt;

&lt;p&gt;There are several possible workarounds and refactoring that could happen in the client driver.&lt;/p&gt;

&lt;p&gt;But the main question is what&apos;s the best practice for wrapping the new Mongo driver in a dll used by a number of consumers?  The current driver implementation makes this difficult if not impossible, so any advice would be appreciated.&lt;/p&gt;

&lt;p&gt;An example app package is attached showing an exe calling a dll containing Mongo functionality.&lt;/p&gt;

&lt;p&gt;Thank you kindly in advance,&lt;br/&gt;
Steve A.&lt;/p&gt;</description>
                <environment></environment>
        <key id="264097">CXX-840</key>
            <summary>Infinite wait in mongo 1.0.7 client if mongo::client::shutdown not explicitly called</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="4">Incomplete</resolution>
                                        <assignee username="mira.carey@mongodb.com">Mira Carey</assignee>
                                    <reporter username="sga">Steve Ahlgren</reporter>
                        <labels>
                            <label>legacy-cxx</label>
                    </labels>
                <created>Tue, 9 Feb 2016 14:40:41 +0000</created>
                <updated>Wed, 23 Mar 2016 12:04:46 +0000</updated>
                            <resolved>Wed, 23 Mar 2016 12:04:46 +0000</resolved>
                                    <version>legacy-1.0.3</version>
                    <version>legacy-1.0.7</version>
                                                    <component>Implementation</component>
                                        <votes>0</votes>
                                    <watches>3</watches>
                                                                                                                <comments>
                            <comment id="1208838" author="acm" created="Sat, 19 Mar 2016 16:49:27 +0000"  >&lt;p&gt;Hi &lt;a href=&quot;https://jira.mongodb.org/secure/ViewProfile.jspa?name=sga&quot; class=&quot;user-hover&quot; rel=&quot;sga&quot;&gt;sga&lt;/a&gt; - Is there anything further we can help you with regarding this ticket? If so, please let us know, otherwise we will close this out.&lt;/p&gt;</comment>
                            <comment id="1179753" author="acm" created="Sat, 20 Feb 2016 16:25:16 +0000"  >&lt;p&gt;Hi &lt;a href=&quot;https://jira.mongodb.org/secure/ViewProfile.jspa?name=sga&quot; class=&quot;user-hover&quot; rel=&quot;sga&quot;&gt;sga&lt;/a&gt; -&lt;/p&gt;

&lt;p&gt;I&apos;d like to better understand the issue you are having and why DLLs are problematic for you. I&apos;m not at all as familiar with the mechanics of DLLs as I am with ELF shared objects, and I&apos;m sort of reasoning by analogy with those, so apologies if I&apos;ve got something wrong - I&apos;m not a Windows expert, really.&lt;/p&gt;

&lt;p&gt;I would expect that during process teardown destructors for objects of file scope in a DLL are executed. I would also expect that if foo.dll depends on bar.dll, that the destruction of global objects in bar.dll would be sequenced before the destruction of global objects in foo.dll.&lt;/p&gt;

&lt;p&gt;So, we have three things in play, really: the application (lets call it app.exe), the DLL that uses mongoclient.dll (lets call it user.dll), and we have the mongoclient.dll itself. I&apos;m imagining that app.exe depends on user.dll, which in turn depends on mongoclient.dll.&lt;/p&gt;

&lt;p&gt;I would imagine that it a file, call it user.cpp, that was compiled into user.dll contained the following code&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;namespace {&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;    // Could use std::unique_ptr if we are using C++11&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;    std::shared_ptr&amp;lt;mongo::GlobalInstance&amp;gt; instance;&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;}&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;void setup_mongo_client(const mongo::client::Options&amp;amp; options) {&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;    instance.reset(new mongo::GlobalInstance(options);&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;}&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;&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 when app.exe terminated, the destructor of instance above would be sequenced before the termination of mongoclient.dll.&lt;/p&gt;

&lt;p&gt;Would something like that not work?&lt;/p&gt;</comment>
                            <comment id="1168011" author="sga" created="Tue, 9 Feb 2016 16:45:49 +0000"  >&lt;p&gt;Hi Jason,&lt;/p&gt;

&lt;p&gt;Thank you for the quick response.  We will definitely consider the new driver.&lt;/p&gt;

&lt;p&gt;Best,&lt;br/&gt;
Steve A.&lt;/p&gt;</comment>
                            <comment id="1168001" author="jason.carey" created="Tue, 9 Feb 2016 16:38:03 +0000"  >&lt;p&gt;Steve,&lt;/p&gt;

&lt;p&gt;As you&apos;ve noted, the legacy C++ driver isn&apos;t very amenable to wrapping.  This is a natural consequence of how it came to be; as a series of improvements to code lifted directly out of the main mongodb source code.  Unfortunately, that&apos;s also unlikely to change, as the legacy driver is no longer under active feature development and new feature support will be focused in our new C++11 driver.&lt;/p&gt;

&lt;p&gt;If you&apos;re looking for a best practice to wrap up a connection to mongodb in a dll, I&apos;d recommend that you consider our new C&amp;#43;&amp;#43;11 driver, or its backend implementation (libmongoc).  The C&amp;#43;&amp;#43;11 driver offers a modern interface and the promise of future support, while the C driver offers a barebones implementation and a commitment to a stable ABI.  While there is a notion of a global instance for our new C&amp;#43;&amp;#43; driver, and an init() / cleanup() pair for the c driver, they manage far more simplistic initialization and don&apos;t own anything like a background thread.&lt;/p&gt;

&lt;p&gt;Regards,&lt;br/&gt;
Jason&lt;/p&gt;</comment>
                    </comments>
                    <attachments>
                            <attachment id="108327" name="mongo_shutdown_defect.zip" size="13923" author="sga" created="Tue, 9 Feb 2016 14:40:41 +0000"/>
                    </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|hrdilr:</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>
                                                                                                                                                                                                                                                                    <customfield id="customfield_10557" key="com.pyxis.greenhopper.jira:gh-sprint">
                        <customfieldname>Sprint</customfieldname>
                        <customfieldvalues>
                                <customfieldvalue id="845">Platforms 10 (02/19/16)</customfieldvalue>

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