<!-- 
RSS generated by JIRA (9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66) at Thu Feb 08 08:53:10 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-829] When using a different port for a localhost, the driver is defaulting back to port 27017 when GMongo is built with ServerAddress objects</title>
                <link>https://jira.mongodb.org/browse/JAVA-829</link>
                <project id="10006" key="JAVA">Java Driver</project>
                    <description>&lt;p&gt;When connecting to a port other than 27017 on localhost, the GMongo driver will not work and default back to 27017 if using an array of ServerAddress objects.  See code below.  The last println prints the same as the second.  It should print the same as the first.&lt;/p&gt;

&lt;p&gt;@Grab(group=&apos;org.mongodb&apos;, module=&apos;mongo-java-driver&apos;, version=&apos;2.10.1&apos;)&lt;/p&gt;

&lt;p&gt;import com.mongodb.*&lt;/p&gt;

&lt;p&gt;//tunnels to another mongo instance&lt;br/&gt;
def mongo = new Mongo(&quot;localhost&quot;,29017)&lt;br/&gt;
println &quot;${mongo.getDatabaseNames()}&quot;&lt;/p&gt;

&lt;p&gt;//my actual local&lt;br/&gt;
mongo = new Mongo(&quot;localhost&quot;,27017)&lt;br/&gt;
println &quot;${mongo.getDatabaseNames()}&quot;&lt;/p&gt;

&lt;p&gt;//BUG - try to do connect to remote cluster (29017 is the same as connected to above)&lt;br/&gt;
mongo = new Mongo(&lt;span class=&quot;error&quot;&gt;&amp;#91;new ServerAddress(&amp;quot;localhost&amp;quot;,29017), new ServerAddress(&amp;quot;localhost&amp;quot;,29018), new ServerAddress(&amp;quot;localhost&amp;quot;,29018)&amp;#93;&lt;/span&gt;)&lt;br/&gt;
println &quot;${mongo.getDatabaseNames()}&quot;&lt;br/&gt;
//result is that this connects to 27017 on localhost instead of the other server addresses&lt;/p&gt;</description>
                <environment>Windows 7, Java 7</environment>
        <key id="75776">JAVA-829</key>
            <summary>When using a different port for a localhost, the driver is defaulting back to port 27017 when GMongo is built with ServerAddress objects</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="-1">Unassigned</assignee>
                                    <reporter username="sdr984">Scott Roberts</reporter>
                        <labels>
                    </labels>
                <created>Fri, 17 May 2013 20:52:30 +0000</created>
                <updated>Tue, 28 May 2013 20:31:06 +0000</updated>
                            <resolved>Tue, 28 May 2013 20:31:06 +0000</resolved>
                                    <version>2.10.1</version>
                                                    <component>Connection Management</component>
                                        <votes>0</votes>
                                    <watches>2</watches>
                                                                                                                <comments>
                            <comment id="347267" author="jeff.yemin" created="Tue, 28 May 2013 20:31:06 +0000"  >&lt;p&gt;OK, we&apos;ll work on the log messages for this.  Thanks for diagnosing.&lt;/p&gt;</comment>
                            <comment id="347252" author="sdr984" created="Tue, 28 May 2013 20:19:05 +0000"  >&lt;p&gt;I guess if that&apos;s how it&apos;s supposed to work.  May be nice to get an error/warning at least if the seed doesn&apos;t resolve the same as the remote.  It was a bit opaque to have the driver connecting to the server entries rather than the one&apos;s I gave it.&lt;/p&gt;</comment>
                            <comment id="347186" author="jeff.yemin" created="Tue, 28 May 2013 19:29:53 +0000"  >&lt;p&gt;OK, I see.  So ok to close this?&lt;/p&gt;</comment>
                            <comment id="347156" author="sdr984" created="Tue, 28 May 2013 19:06:51 +0000"  >&lt;p&gt;Ok, so what&apos;s happening in the second scenario is that the server is passing back DNS names that I have added in my hosts file to point to localhost (because there is a firewall between my dev machine and the db, thus the tunnel).  The names passed back reference 27017 since they don&apos;t have to do any tunnel shenanigans to talk to each other.  When those names come back and resolve, they resolve to my local database.  So in any testing that I do between my local machine and a firewalled remote db should be only connecting to the master, not the replica set.  &lt;/p&gt;</comment>
                            <comment id="347133" author="jeff.yemin" created="Tue, 28 May 2013 18:39:33 +0000"  >&lt;p&gt;There is a very big difference in behavior between the constructor that takes a single ServerAddress and the one that takes a List&amp;lt;ServerAddress&amp;gt;.  In the latter case, the List is treated as a seed list to the replica set, and the driver will attempt to discover the other members of the replica set, based on calls to the &lt;a href=&quot;http://docs.mongodb.org/manual/reference/command/isMaster/&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;ismaster&lt;/a&gt; command for each member of the seed list.  It&apos;s for this reason that the driver will use the host names as provided by the response to the ismaster command.&lt;/p&gt;

&lt;p&gt;The constructor that takes a single ServerAddress should only be used if you are either connecting to a standalone, a single mongos, or, in rare cases, a single member of a replica set.  The latter is typically only done if you are doing some administrative tasks where you know exactly which server you want to connect to (e.g., to run the &lt;a href=&quot;http://docs.mongodb.org/manual/reference/command/compact/&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;compact&lt;/a&gt; command on it). &lt;/p&gt;

&lt;p&gt;That said, I agree with your last assertion, and I&apos;m still not sure what&apos;s going on that would cause you to see those results.&lt;/p&gt;

&lt;p&gt;We will try to reproduce, but off hand I don&apos;t see how the driver would end up connecting to localhost:27017.  Does the server that you&apos;re running on have network access to tldod01, tldod02, and tldod03?&lt;/p&gt;

&lt;p&gt;Also, can you please provide application logs?  The driver logs a bunch of messages about the replica set discovery process.&lt;/p&gt;
</comment>
                            <comment id="347108" author="sdr984" created="Tue, 28 May 2013 18:17:07 +0000"  >&lt;p&gt;To a user of the driver, I don&apos;t think the expectation is that these two would (or could) provide different results.&lt;/p&gt;

&lt;p&gt;Mongo mongo = new Mongo(&quot;localhost&quot;,29017);&lt;br/&gt;
System.out.println(mongo.getDatabaseNames());&lt;/p&gt;

&lt;p&gt;Mongo mongo3 = new Mongo(Arrays.asList(new ServerAddress(&quot;localhost&quot;,29017)));&lt;br/&gt;
System.out.println(mongo3.getDatabaseNames());&lt;/p&gt;</comment>
                            <comment id="347105" author="sdr984" created="Tue, 28 May 2013 18:14:08 +0000"  >&lt;p&gt;So are you saying this is expected?  Why would I even add servers to a connection list if the driver doesn&apos;t plan on obeying them?  I&apos;d expect a list of servers to behave the same as a single server that I give to the same Mongo object.&lt;/p&gt;</comment>
                            <comment id="347094" author="jeff.yemin" created="Tue, 28 May 2013 18:06:45 +0000"  >&lt;p&gt;I&apos;m not sure exactly what&apos;s going on, but this is just not going to work properly.  When connecting to a replica set using the constructor that takes a List, the driver will try to connect to all members of the replica set with the DNS names that appear in db.isMaster(), regardless of the provided seed list.  Tunneling is not going to work.&lt;/p&gt;</comment>
                            <comment id="347038" author="sdr984" created="Tue, 28 May 2013 17:20:11 +0000"  >&lt;p&gt;requested test output&lt;/p&gt;</comment>
                            <comment id="347004" author="jeff.yemin" created="Tue, 28 May 2013 16:37:08 +0000"  >&lt;p&gt;Please connect via the shell to both ports (mongo --port 27017, mongo --port 29017) and run db.isMaster() and rs.status(), then post all the output to this ticket.&lt;/p&gt;</comment>
                            <comment id="346998" author="sdr984" created="Tue, 28 May 2013 16:31:07 +0000"  >&lt;p&gt;even this simpler one breaks&lt;/p&gt;</comment>
                            <comment id="346994" author="sdr984" created="Tue, 28 May 2013 16:25:53 +0000"  >&lt;p&gt;This replicates the error in pure java.&lt;/p&gt;</comment>
                            <comment id="346991" author="sdr984" created="Tue, 28 May 2013 16:25:31 +0000"  >&lt;p&gt;Yes, I was able to replicate with a pure java program as well.  See the attached code.&lt;/p&gt;
</comment>
                            <comment id="344273" author="sdr984" created="Fri, 24 May 2013 02:07:34 +0000"  >&lt;p&gt;Gmongo is nothing more than a lightweight wrapper on the java driver.  I&apos;m out of town for the weekend, but can write some simple java code when I get back to see if I can replicate without the wrapper.  It is possible that it is a gmongo issue, but given how they structure it, it would surprise me.&lt;/p&gt;</comment>
                            <comment id="343786" author="jeff.yemin" created="Thu, 23 May 2013 15:53:38 +0000"  >&lt;p&gt;Are you able to reproduce this using just the Java driver, without GMongo?  I&apos;ve never seen anything like this in the Java driver itself.&lt;/p&gt;</comment>
                            <comment id="338369" author="sdr984" created="Fri, 17 May 2013 21:21:56 +0000"  >&lt;p&gt;Even if you have a single in the list it connects to the wrong db.  These connect to different mongo instances, but should connect to the same:&lt;/p&gt;

&lt;p&gt;mongo = new Mongo(new ServerAddress(&quot;localhost&quot;,29017))&lt;br/&gt;
println &quot;${mongo.getDatabaseNames()}&quot;&lt;/p&gt;

&lt;p&gt;mongo = new Mongo(&lt;span class=&quot;error&quot;&gt;&amp;#91;new ServerAddress(&amp;quot;localhost&amp;quot;,29017)&amp;#93;&lt;/span&gt;)&lt;br/&gt;
println &quot;${mongo.getDatabaseNames()}&quot;&lt;/p&gt;</comment>
                            <comment id="338361" author="sdr984" created="Fri, 17 May 2013 21:14:16 +0000"  >&lt;p&gt;MongoURI method seems to have same problems;&lt;/p&gt;

&lt;p&gt;this works:&lt;br/&gt;
mongo = new Mongo(new MongoURI(&quot;mongodb://localhost:29017&quot;))&lt;br/&gt;
this doesn&apos;t:&lt;br/&gt;
mongo = new Mongo(new MongoURI(&quot;mongodb://localhost:29017,localhost:29018,localhost:29019&quot;))&lt;/p&gt;</comment>
                            <comment id="338350" author="sdr984" created="Fri, 17 May 2013 21:03:23 +0000"  >&lt;p&gt;To be more clear about my test setup.  I have a local single node mongo instance running on 27017.  I have an SSH tunnel setup on 29017, 29018, 29019 to another server.  The connection to one remote works, the connection to the remote cluster connects me to my local 27017 even though I&apos;ve specified other ports.&lt;/p&gt;</comment>
                            <comment id="338343" author="sdr984" created="Fri, 17 May 2013 20:56:14 +0000"  >&lt;p&gt;note that even if the first example is changed to a single ServerAddress it still does the same thing.&lt;/p&gt;

&lt;p&gt;//tunnels to another mongo instance&lt;br/&gt;
def mongo = new Mongo(new ServerAddress(&quot;localhost&quot;,29017))&lt;br/&gt;
println &quot;${mongo.getDatabaseNames()}&quot;&lt;/p&gt;

&lt;p&gt;//my actual local&lt;br/&gt;
mongo = new Mongo(&quot;localhost&quot;,27017)&lt;br/&gt;
println &quot;${mongo.getDatabaseNames()}&quot;&lt;/p&gt;

&lt;p&gt;//try to do connect to remote cluster (29017 is the same as connected to above)&lt;br/&gt;
mongo = new Mongo(&lt;span class=&quot;error&quot;&gt;&amp;#91;new ServerAddress(&amp;quot;localhost&amp;quot;,29017), new ServerAddress(&amp;quot;localhost&amp;quot;,29018), new ServerAddress(&amp;quot;localhost&amp;quot;,29019)&amp;#93;&lt;/span&gt;)&lt;br/&gt;
println &quot;${mongo.getDatabaseNames()}&quot;&lt;/p&gt;</comment>
                    </comments>
                    <attachments>
                            <attachment id="27308" name="TestMongo.java" size="836" author="sdr984" created="Tue, 28 May 2013 16:31:07 +0000"/>
                            <attachment id="27307" name="TestMongo.java" size="896" author="sdr984" created="Tue, 28 May 2013 16:25:53 +0000"/>
                            <attachment id="27311" name="test-output.txt" size="3172" author="sdr984" created="Tue, 28 May 2013 17:20:11 +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|hrny9r:</customfieldvalue>

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