Join GitHub today
GitHub is home to over 50 million developers working together to host and review code, manage projects, and build software together.Sign up
GitHub is where the world builds software
Millions of developers and companies build, ship, and maintain their software on GitHub — the largest and most advanced development platform in the world.
database/sql: Go 2: Is context cancellation on QueryContext meant to cancel row.Scan? #28842
The issue I had was that I intended the context to cancel the query only. Once the query completed, and since the context hadn't cancelled while the query was in progress, I didn't expect it would interfere with gathering the results.
Perhaps the documentation should make clear that query cancellation will have possible after-effects after the actual
One could argue that my interpretation is better because if I want the query to cancel, the status quo does what I believed it would do.
If I want the context to cancel the scan loop as well, I can easily check the
Agreed. So do I.
I disagree with your interpretation of Go API design with regards to context cancellation.
My contention is when you provide a context to
Under the status quo, when the context is cancelled after the function returns - but during the scan-loop, it is interfering. It is preventing the scan from working during the scan loop.
My suggestion makes it trivial to implement the current status quo implementation. My suggestion also gives the flexibility to treat the scanning process independently of the query execution.
I feel it is also more consistent with people's intuitive understanding of how context cancellation should work.
If I have successfully persuaded you, then the follow-up question is what to do with the Go 1 backward compatibility promise. Do you keep it the way it is and fix it for Go 2? Or do you consider it a mistake in the first place and update it for Go 1 to operate in line with what I believe is the correct interpretation?
Perhaps @robpike can shed light on how context cancellation should be interpreted. I looked in the specs and could not find a definitive interpretation.
Now on a separate but related note, if my interpretation is actually incorrect or deemed incorrect, then the documentation should state for