[GODRIVER-373] DocumentResult does not close cursor Created: 20/Apr/18  Updated: 28/Oct/23  Resolved: 13/Sep/18

Status: Closed
Project: Go Driver
Component/s: CRUD
Affects Version/s: None
Fix Version/s: 0.0.14

Type: Bug Priority: Major - P3
Reporter: Eric Daniels (Inactive) Assignee: Matthew Chiaravalloti
Resolution: Fixed Votes: 0
Labels: neweng, newgrad
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Epic Link: Go FY2019Q3 Quick Wins

 Description   

https://github.com/mongodb/mongo-go-driver/blob/master/mongo/document_result.go#L43 should have a defer dr.cur.Close(context.Background()) right before it. This function may need a backwards breaking change of requiring a context as a param to get API parity.



 Comments   
Comment by Githook User [ 13/Sep/18 ]

Author:

{'name': 'Matthew Chiaravalloti', 'email': 'matthew.chiaravalloti@mongodb.com', 'username': 'mattChiaravalloti'}

Message: Add deferred call to close DocumentResult's cursor

GODRIVER-373

Change-Id: I7addfb359952a5abfccd40c59bf294d3e30be16a
Branch: master
https://github.com/mongodb/mongo-go-driver/commit/e0b7d070208df5f52a9933c2c9761ebb2b0ad65d

Comment by Jeffrey Yemin [ 23/Apr/18 ]

For findOne style operations, the driver should automatically set the limit to -1 (or maybe 1...) and in that case the server will send a single document and no cursorId, making cursor.close essentially a no-op.

But, you should still close the cursor here, because in the future cursor will hold other resources besides the server-side cursor (e.g. sessions).

Generated at Thu Feb 08 08:34:04 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.