Repository navigation
Conversation
…eled Cursor sends rows over an unbuffered channel from a background goroutine. If the consumer stops ranging early (break/return), the goroutine blocks forever on the send, keeping the rows and the connection open. The send now also selects on the query context, so canceling the context passed to WithContext lets the goroutine exit and close the rows. Applies to both orm.Query.Cursor and db.Query.Cursor.
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #1580 +/- ##
==========================================
+ Coverage 72.91% 73.34% +0.43%
==========================================
Files 412 412
Lines 26893 26909 +16
==========================================
+ Hits 19608 19736 +128
+ Misses 7283 7171 -112
Partials 2 2 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
JGamboa
marked this pull request as ready for review
October 18, 2026 23:47
Contributor
Author
|
Review Ready |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
📑 Description
Closes goravel/goravel#1016
orm.Query.Cursor()anddb.Query.Cursor()send rows on an unbuffered channel. When the consumer stops early (abreakorreturn), the producer goroutine blocks on the send forever, so the rows are never closed and the connection never returns to the pool.This is a backward-compatible fix, with no signature change:
select { case ch <- row: case <-ctx.Done(): return }. Canceling the context given toWithContext, or a request context ending, lets the goroutine exit and close the rows. Applied to both the ORM and the DB builder.Cursordoc comments in the contracts explain that the context must be canceled when stopping early.Breaking out without canceling the context still can't be detected without changing the API. The issue lists the options, such as a new
iter.Seq2-based method as a follow-up.✅ Checks
TestCursor_BreakWithCanceledContextintests/query_test.goandtests/db_test.go. It fails on master and passes here on MySQL, PostgreSQL, SQL Server and SQLite.