Unverified Commit ae43dcd0 authored by Silvio Moioli's avatar Silvio Moioli
Browse files

Close Rows object if the context is canceled before deferred function

This is useful in the following situation:

* `query` function gets called
* SQL query is executed correctly, the `r` result (Rows) is set
* after that, but before `query` returns, `ctx` is canceled
* `interruptOnDone`’s goroutine catches the cancelation and signals
  the completion back to `query` by turning the atomic signaling
  variable `done` to 1
* `query` finishes and returns
* the anonymous deferred function patched here is popped off the
  deferred stack and executed

The current code, seeing that `done` is not zero, will overwrite `r`
(Rows) with `nil`, and that implies the Rows can never be `Close`d.

Unclosed Rows mean that read transactions never finish, and that
blocks the checkpointer process and cause the WAL to grow unbounded,
and other read queries to slow down unbounded.

https://sqlite.org/wal.html#avoiding_excessively_large_wal_files
("Checkpoint Starvation")
parent 482dd8ac
Loading
Loading
Loading
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment