<!-- 
RSS generated by JIRA (9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66) at Thu Feb 08 08:53:04 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>[JAVA-788] Detecting Server Going Away?</title>
                <link>https://jira.mongodb.org/browse/JAVA-788</link>
                <project id="10006" key="JAVA">Java Driver</project>
                    <description>&lt;p&gt;The Java driver is great when everything goes right.  However, the weakness can be seen when things start to go wrong.&lt;/p&gt;

&lt;p&gt;Let me illustrate with an example.  A very simple one ... detecting when the server is available.  You can&apos;t!&lt;/p&gt;

&lt;p&gt;Say for example you wanted to make sure the server was available (maybe you start your client before the server, or the server goes away for maintenance for a few moments (backup)).&lt;/p&gt;

&lt;p&gt;Take the following piece of code:&lt;/p&gt;

&lt;p&gt;try{&lt;br/&gt;
  mongo.getConnector().requestEnsureConnection();&lt;br/&gt;
}catch(Exception e){&lt;br/&gt;
  // never thrown&lt;br/&gt;
}&lt;/p&gt;

&lt;p&gt;Why is the following exception (see below) masked?   It is logged out to the JUL but that is of no use to the calling application.&lt;/p&gt;

&lt;p&gt;The mongo.getConnector().isOpen() also suffers the same fate.&lt;/p&gt;

&lt;p&gt;Why on earth are these exceptions masked?   This is Java 101.&lt;/p&gt;

&lt;p&gt;WARNING: Exception executing isMaster command on /127.0.0.1:27017&lt;br/&gt;
java.io.IOException: couldn&apos;t connect to &lt;span class=&quot;error&quot;&gt;&amp;#91;/127.0.0.1:27017&amp;#93;&lt;/span&gt; bc:java.net.ConnectException: Connection refused: connect&lt;br/&gt;
    at com.mongodb.DBPort._open(DBPort.java:214)&lt;br/&gt;
    at com.mongodb.DBPort.go(DBPort.java:107)&lt;br/&gt;
    at com.mongodb.DBPort.go(DBPort.java:88)&lt;br/&gt;
    at com.mongodb.DBPort.findOne(DBPort.java:143)&lt;br/&gt;
    at com.mongodb.DBPort.runCommand(DBPort.java:148)&lt;br/&gt;
    at com.mongodb.DBTCPConnector.initDirectConnection(DBTCPConnector.java:548)&lt;br/&gt;
    at com.mongodb.DBTCPConnector.checkMaster(DBTCPConnector.java:527)&lt;br/&gt;
    at com.mongodb.DBTCPConnector.requestEnsureConnection(DBTCPConnector.java:129)&lt;br/&gt;
    at com.profiler.ProfilerExtension.run(ProfilerExtension.java:126)&lt;br/&gt;
    at java.lang.Thread.run(Thread.java:619)&lt;/p&gt;


&lt;p&gt;So the question is, how does one handle the fact a server has gone away?   What is the magic here to determine what is what?&lt;/p&gt;</description>
                <environment></environment>
        <key id="68559">JAVA-788</key>
            <summary>Detecting Server Going Away?</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="3">Duplicate</resolution>
                                        <assignee username="-1">Unassigned</assignee>
                                    <reporter username="alanwilliamson">Alan Williamson</reporter>
                        <labels>
                    </labels>
                <created>Fri, 15 Mar 2013 14:52:14 +0000</created>
                <updated>Fri, 12 Jul 2013 14:26:47 +0000</updated>
                            <resolved>Fri, 12 Jul 2013 14:26:28 +0000</resolved>
                                    <version>2.10.1</version>
                                                    <component>Connection Management</component>
                                        <votes>0</votes>
                                    <watches>3</watches>
                                                                                                                <comments>
                            <comment id="379806" author="jeff.yemin" created="Fri, 12 Jul 2013 14:26:28 +0000"  >&lt;p&gt;Since I didn&apos;t get any objections, I&apos;m going to close this as a duplicate of &lt;a href=&quot;https://jira.mongodb.org/browse/JAVA-805&quot; title=&quot;Make connection pool and connection state observable&quot; class=&quot;issue-link&quot; data-issue-key=&quot;JAVA-805&quot;&gt;&lt;del&gt;JAVA-805&lt;/del&gt;&lt;/a&gt;, but please comment if you see a better solution.&lt;/p&gt;</comment>
                            <comment id="367001" author="jeff.yemin" created="Tue, 25 Jun 2013 04:11:48 +0000"  >&lt;p&gt;What do you think about marking this as a duplicate of &lt;a href=&quot;https://jira.mongodb.org/browse/JAVA-805&quot; title=&quot;Make connection pool and connection state observable&quot; class=&quot;issue-link&quot; data-issue-key=&quot;JAVA-805&quot;&gt;&lt;del&gt;JAVA-805&lt;/del&gt;&lt;/a&gt;?  In my opinion that&apos;s the best we can do.&lt;/p&gt;</comment>
                            <comment id="290296" author="jeff.yemin" created="Fri, 15 Mar 2013 17:46:39 +0000"  >&lt;p&gt;That method just tells you whether you&apos;ve called Mongo.close().&lt;/p&gt;

&lt;p&gt;Why don&apos;t you just send your command and if it fails you know that the server is unavailable?  You have to handle failures anyway, as there is no guarantee that the server won&apos;t go down between the ping and the next command you send.  &lt;/p&gt;</comment>
                            <comment id="290273" author="alanwilliamson" created="Fri, 15 Mar 2013 17:37:32 +0000"  >&lt;p&gt;On that vein the mongo.getConnector().isOpen() is another method that doesn&apos;t help either in this particular instance.&lt;/p&gt;

&lt;p&gt;Since the background thread is continually listening, then to even know if that connection is still alive is a huge leap forward in performance/efficiency than having to always send a &quot;ping&quot; before you send your command.&lt;/p&gt;</comment>
                            <comment id="290265" author="jeff.yemin" created="Fri, 15 Mar 2013 17:30:15 +0000"  >&lt;p&gt;Since servers can go off-line at any time, the only guarantee the driver provides is that when you actually try to communicate with the server (by initiating a command, a query, an insert, etc), you will get an exception if it fails.  So one thing you might try is a ping command, e.g.&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;public static void main(String[] args) throws UnknownHostException {&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;        Mongo m = new Mongo(&quot;localhost:3000&quot;);&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;        try {&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;            m.getDB(&quot;admin&quot;).command(&quot;ping&quot;);&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;        } catch (MongoException.Network e) {&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;            // You should get this exception if the server is unavailable&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;            e.printStackTrace();&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;DB.requestEnsureConnection is a bit of a misnomer, and could certainly be documented better.  All it guarantees is that the current thread reserves one of the pooled DBPort instances, each of which wraps a Socket.  But the socket is not actually opened until the first time you try to use it to perform some operation.&lt;/p&gt;

</comment>
                    </comments>
                <issuelinks>
                            <issuelinktype id="10010">
                    <name>Duplicate</name>
                                            <outwardlinks description="duplicates">
                                        <issuelink>
            <issuekey id="71639">JAVA-805</issuekey>
        </issuelink>
                            </outwardlinks>
                                                        </issuelinktype>
                    </issuelinks>
                <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|hrmq87:</customfieldvalue>

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