Repository navigation
fix: defer context to prevent goroutine leak - #7847
Open
System-Glitch wants to merge 1 commit into
Open
System-Glitch wants to merge 1 commit into
System-Glitch wants to merge 1 commit into
Conversation
System-Glitch
marked this pull request as draft
August 31, 2026 09:24
System-Glitch
force-pushed
the
fix/context-leak
branch
from
August 31, 2026 09:29
0e77497 to
877fa1e
Compare
System-Glitch
marked this pull request as ready for review
August 31, 2026 09:29
System-Glitch
force-pushed
the
fix/context-leak
branch
2 times, most recently
from
August 31, 2026 09:46
50cae17 to
832eb27
Compare
Author
|
I have a unit test suite for this, based on go-sqlmock and testing/synctest. However there aren't any test of this kind in the project yet and that would add a dependency in the go.mod. I can add the test if you want, just say the word! |
System-Glitch
force-pushed
the
fix/context-leak
branch
from
September 24, 2026 09:22
832eb27 to
bd999b5
Compare
System-Glitch
force-pushed
the
fix/context-leak
branch
from
September 24, 2026 09:24
bd999b5 to
3f0ce44
Compare
Author
|
Rebased and fixed lint issue. |
This branch has not been deployed
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.
What did this pull request do?
DefaultContextTimeoutis set in the config.BEGINreturned. Each query will have its own timeout context and statements can be re-used safely.db.Scan(), I moved the rows scanning into a new callback "gorm:scan_rows".rows.Next()indb.Scan(), leading to a context canceled error.db.Row()anddb.Rows()because the new callback doesn't activate in those cases.DefaultContextTimeoutoption does nothing ondb.Row()anddb.Rows(). Developers need to manage the context and timeout themselves since they are scanning manually.User Case Description
DefaultContextTimeoutsetting is great but causes context leaks. Fixing this issue makes the feature a very useful one.Related to: