Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

database/sql: document that Rows.Close must be called #46863

Open
adonovan opened this issue Jun 21, 2021 · 1 comment
Open

database/sql: document that Rows.Close must be called #46863

adonovan opened this issue Jun 21, 2021 · 1 comment
Labels
Documentation NeedsFix
Milestone

Comments

@adonovan
Copy link
Member

@adonovan adonovan commented Jun 21, 2021

Failure to call Rows.Close leads to a resource leak. Although the usage example calls defer rows.Close(), it's easy for a caller of, say, QueryContext not to realize that the Rows result is Closeable and to forget to call it.

The documentation of Rows, and any function that returns a Rows, should state that the caller is responsible for calling Close.

Also, the examples suggest that errors from Close may be ignored for read-only queries but should not be ignored for updates. In this respect the database is analogous to a readable or writable file; this too is worth pointing out explicitly.

See also #33938.

@toothrot toothrot added this to the Backlog milestone Jun 21, 2021
@toothrot toothrot added the NeedsFix label Jun 21, 2021
@golang golang deleted a comment Jul 1, 2021
@gopherbot
Copy link

@gopherbot gopherbot commented Jul 12, 2021

Change https://golang.org/cl/333989 mentions this issue: database/sql: document that *Rows must be closed after Query

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Documentation NeedsFix
Projects
None yet
Development

No branches or pull requests

3 participants