Skip to content

Why call rows.Close() could take long time #1452

Answered by jackc
stasvo asked this question in Q&A
Discussion options

You must be logged in to vote

The PostgreSQL server will still send all the rows.

Interesting that duration of rows.Close() in this case in same as duration which I will have if will process all elements of rows.Next() loop without break it.

That's basically what pgx is doing. It still has to read everything that comes over the wire until it receives the ReadyForQuery message.

You can use https://pkg.go.dev/github.com/jackc/pgx/[email protected]/pgconn#PgConn.CancelRequest to send the PostgreSQL server a cancel request message. However, due to limitations of the PostgreSQL protocol, it is difficult to use in a perfectly reliable manner.

An alternative is to cancel the context used for your query. However, partially due to t…

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@stasvo
Comment options

Answer selected by stasvo
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants