2 ms·
>> Instead, make sure that every SQL operation in your app is using the QueryContext / ExecContext interfaces I've been wondering if this is indeed a best prac
by zkirill 6y ago
>> Instead, make sure that every SQL operation in your app is using the QueryContext / ExecContext interfaces
I've been wondering if this is indeed a best practice or something that should be used only when necessary. Should every database query really abort if the connection to the client fails?
In addition, if you follow this advice you now need to check if the returned error is context.Cancelled which warrants an HTTP 400 response.
- dullgiulio 6y agoOf course it is up to the application to decide case-by-case. Just keep in mind that if your query is started by a user request, but does not need to terminate in the context of the user request that triggered it, you can move the query to a separate goroutine and decouple it completely from the triggering user request. Also, aborting a query is safe: the transaction gets rolled back, removing unwanted side effects. You cannot do harm by cancelling, bu you can do harm if you don't cancel.