[bugfix] add workaround for Xsqlite_interrupt() permanently breaking connection #2731
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
After our
modernc.org/sqlite
version bump v1.28.0 -> v1.29.2 (further narrowed to be changes in v1.29.0 -> v1.29.2) we started experiencing a regresion, in which canceling a context on an ongoing database query in the right way now causes anXsqlite_interrupt()
call to be made internally, which returns error codeSQLITE_INTERRUPT
on that connection's running query. Oddly, that then continually gets returned by all subsequent queries on that connection, leaving the instance in a broken state.We still haven't narrowed this down to an SQLite library change revealing a bug on our end, or whether it's an SQLite library bug.
This is a quick workaround, which works as follows (text copied from matrix dev chat):
"okay i've found a workaround for now. so between v1.29.0 and v1.29.2 is that slightly tweaked interruptOnDone() behaviour, which causes interrupt to (imo, correctly) get called when a context is cancelled to cancel the running query. the issue is that every single query after that point seems to still then return interrupted. so as you thought, maybe that query count isn't being decremented. i don't think it's our code, but i haven't ruled it out yet.
the workaround for now is adding to our sqlite error processor to replace an SQLITE_INTERRUPTED code with driver.ErrBadConn, which hints to the golang sql package that the conn needs to be closed and a new one opened"
Checklist
Please put an x inside each checkbox to indicate that you've read and followed it:
[ ]
->[x]
If this is a documentation change, only the first checkbox must be filled (you can delete the others if you want).
go fmt ./...
andgolangci-lint run
.