<!-- 
RSS generated by JIRA (9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66) at Thu Feb 08 08:36:56 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-1697] Cursor.Close accepts context which could result in cancelling the close operation</title>
                <link>https://jira.mongodb.org/browse/GODRIVER-1697</link>
                <project id="14289" key="GODRIVER">Go Driver</project>
                    <description>&lt;p&gt;mongodb-go-driver accepts a&#160;&lt;tt&gt;context&lt;/tt&gt;&#160;for the&#160;&lt;tt&gt;Cursor.Close&lt;/tt&gt;,&#160;&lt;tt&gt;Session.EndSession&lt;/tt&gt;, transaction, etc. This looks like a problem to me, as context is used for cancellation and cancelling a close operation is not really desired (Leaking the cursor).&lt;/p&gt;

&lt;p&gt;I can try just passing&#160;&lt;tt&gt;context.Background()&lt;/tt&gt;&#160;specifically to such close methods, but that seems very error prone.&lt;/p&gt;

&lt;p&gt;You would often use context by taking the HTTP request context, which gets cancelled if the connection is severed for any reason, and possibly add a Mongo session on top of it if desired (&lt;tt&gt;UseSession&lt;/tt&gt;). If I then just pass&#160;&lt;tt&gt;context.Background()&lt;/tt&gt;, it won&apos;t use the session for those close operations which I&apos;m not sure is correct or even going to work.&lt;/p&gt;</description>
                <environment></environment>
        <key id="1414463">GODRIVER-1697</key>
            <summary>Cursor.Close accepts context which could result in cancelling the close operation</summary>
                <type id="4" iconUrl="https://jira.mongodb.org/secure/viewavatar?size=xsmall&amp;avatarId=14710&amp;avatarType=issuetype">Improvement</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="divjot.arora@mongodb.com">Divjot Arora</assignee>
                                    <reporter username="shay@codeocean.com">Shay Katz</reporter>
                        <labels>
                    </labels>
                <created>Mon, 20 Jul 2020 10:39:29 +0000</created>
                <updated>Fri, 27 Oct 2023 13:16:26 +0000</updated>
                            <resolved>Thu, 23 Jul 2020 16:53:46 +0000</resolved>
                                    <version>1.3.5</version>
                                                                        <votes>0</votes>
                                    <watches>1</watches>
                                                                                                                <comments>
                            <comment id="3299218" author="divjot.arora" created="Thu, 23 Jul 2020 16:53:46 +0000"  >&lt;p&gt;Hi &lt;a href=&quot;https://jira.mongodb.org/secure/ViewProfile.jspa?name=shay%40codeocean.com&quot; class=&quot;user-hover&quot; rel=&quot;shay@codeocean.com&quot;&gt;shay@codeocean.com&lt;/a&gt;,&lt;/p&gt;

&lt;p&gt;The context.Context type in Go is an overloaded concept. As you mention, it is used for timeouts/cancellation, but it can also be used to store a map of values associated with an operation via the context.WithValue function. This is an extremely useful functionality and we&apos;ve heard of some users combining it with our command monitoring API (&lt;a href=&quot;https://pkg.go.dev/go.mongodb.org/mongo-driver/mongo/options?tab=doc#ClientOptions.SetMonitor&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/options?tab=doc#ClientOptions.SetMonitor&lt;/a&gt;&#160;and&#160;&lt;a href=&quot;https://pkg.go.dev/go.mongodb.org/mongo-driver/event?tab=doc#CommandMonitor&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/event?tab=doc#CommandMonitor&lt;/a&gt;) to do operation tracing. Removing contexts from the functions you mention would be a backwards-breaking API change and could break things for users who are doing this.&lt;/p&gt;

&lt;p&gt;You can use &lt;tt&gt;context.Background()&lt;/tt&gt; for these operations. &lt;tt&gt;Cursor.Close&lt;/tt&gt;, &lt;tt&gt;Session.EndSession&lt;/tt&gt; and &lt;tt&gt;Session.AbortTransaction&lt;/tt&gt; all get the session from elsewhere rather than extracting it from the context. Version 1.4.0 of the driver will also include a non-callback based sessions API, so you would be able to create a new SessionContext based on &lt;tt&gt;context.Background()&lt;/tt&gt; if needed.&lt;/p&gt;

&lt;p&gt;Given all of this, I&apos;m going to close out this ticket. Feel free to leave another comment or open a new ticket if you have any suggestions!&lt;/p&gt;

&lt;p&gt;&amp;#8211; Divjot&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|hxiksv:</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>