<!-- 
RSS generated by JIRA (9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66) at Thu Feb 08 08:37:08 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>[GODRIVER-1792] Dial TCP failure with concurrent queries</title>
                <link>https://jira.mongodb.org/browse/GODRIVER-1792</link>
                <project id="14289" key="GODRIVER">Go Driver</project>
                    <description>&lt;p&gt;I have an application that spins up a lot of concurrent queries to the database across multiple threads. To begin with it happily queries and returns successfully within a few milliseconds for each query. However, after a short while of running (approx. 30 seconds), the `collection.Find` command begins returning the following error intermittently:&lt;/p&gt;

&lt;p&gt;&lt;tt&gt;connection() : dial tcp 127.0.0.1:27017: connectex: Only one usage of each socket address (protocol/network address/port) is normally permitted.&lt;/tt&gt;&lt;/p&gt;

&lt;p&gt;This kind of network error would usually imply to me that it was trying to listen on that socket but the socket was already in use - not sure how that really applies in the network level of the mongo go driver though?&lt;/p&gt;

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

&lt;p&gt;Each separate part of the application does its own `mongo.Connect` and then calls `client.Disconnect` when it is completed. There are only ever around a dozen or so clients connected at the same time, but its fair to say that a lot of separate queries will be taking place on the clients concurrently, as well as multiple clients being around while in use.&lt;/p&gt;

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

&lt;p&gt;Is this a bug or am I doing something wrong?&lt;/p&gt;</description>
                <environment>Windows 64 bit</environment>
        <key id="1541631">GODRIVER-1792</key>
            <summary>Dial TCP failure with concurrent queries</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="-1">Unassigned</assignee>
                                    <reporter username="lotawif879@aalyaa.com">Liam Brown</reporter>
                        <labels>
                    </labels>
                <created>Fri, 13 Nov 2020 16:36:24 +0000</created>
                <updated>Fri, 27 Oct 2023 13:16:25 +0000</updated>
                            <resolved>Mon, 16 Nov 2020 21:02:32 +0000</resolved>
                                    <version>1.4.1</version>
                                                    <component>Connections</component>
                    <component>Networking</component>
                                        <votes>0</votes>
                                    <watches>2</watches>
                                                                                                                <comments>
                            <comment id="3491280" author="JIRAUSER1257620" created="Mon, 16 Nov 2020 09:15:42 +0000"  >&lt;p&gt;Thanks Kevin for the quick and very helpful answer. Verified with netstat -a that that is in fact what is going on here. I&apos;ll try sharing Clients and see how that goes, or take other steps with my application code to work around this.&lt;/p&gt;

&lt;p&gt;Please feel free to close this as it is clearly not an issue with the Go Driver.&lt;/p&gt;

&lt;p&gt;Thanks again.&lt;/p&gt;</comment>
                            <comment id="3489661" author="kevin.albertson" created="Fri, 13 Nov 2020 17:16:50 +0000"  >&lt;p&gt;Hi &lt;a href=&quot;https://jira.mongodb.org/secure/ViewProfile.jspa?name=lotawif879%40aalyaa.com&quot; class=&quot;user-hover&quot; rel=&quot;lotawif879@aalyaa.com&quot;&gt;lotawif879@aalyaa.com&lt;/a&gt;, thank you for the report!&lt;/p&gt;

&lt;p&gt;At a glance, this may be an issue with sockets entering the TIME_WAIT state on Windows.&lt;br/&gt;
See: &lt;a href=&quot;https://help.socketlabs.com/docs/how-to-fix-error-only-one-usage-of-each-socket-address-protocolnetwork-addressport-is-normally-permitted&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;https://help.socketlabs.com/docs/how-to-fix-error-only-one-usage-of-each-socket-address-protocolnetwork-addressport-is-normally-permitted&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;You can try running &lt;tt&gt;netstat -a&lt;/tt&gt; to verify this.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Each separate part of the application does its own `mongo.Connect` and then calls `client.Disconnect` when it is completed. There are only ever around a dozen or so clients connected at the same time, but its fair to say that a lot of separate queries will be taking place on the clients concurrently, as well as multiple clients being around while in use.&lt;/p&gt;&lt;/blockquote&gt;

&lt;p&gt;Using separate Clients would contribute to a higher amount connections. And recreating them would end up recreating the connection pool to each server. If this is an issue with sockets entering the TIME_WAIT state, try sharing Clients between goroutines, as it is safe and recommended to do so: &lt;a href=&quot;https://pkg.go.dev/go.mongodb.org/mongo-driver/mongo#Client&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;https://pkg.go.dev/go.mongodb.org/mongo-driver/mongo#Client&lt;/a&gt;. That will share each server&apos;s connection pool with each goroutine and should reduce the number of total connections. You can also modify the maximum number of connections a single Client will create to a server by setting a &lt;tt&gt;maxPoolSize&lt;/tt&gt;: &lt;a href=&quot;https://pkg.go.dev/go.mongodb.org/mongo-driver@v1.4.3/mongo/options#ClientOptions.SetMaxPoolSize&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;https://pkg.go.dev/go.mongodb.org/mongo-driver@v1.4.3/mongo/options#ClientOptions.SetMaxPoolSize&lt;/a&gt;&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|hy3ct3:</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>