Skip to content

Commit 2fe6882

Browse files
committed
Add note about calling interrupt and close immediately
Closes: #315 You can not call close immediately after interrupt. It will result in undefined behavior. Instead, shim a small `Process.sleep/1` in and it should mitigate the issue.
1 parent f09f773 commit 2fe6882

File tree

3 files changed

+13
-1
lines changed

3 files changed

+13
-1
lines changed

CHANGELOG.md

+3
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@
44

55
- changed: Removed `Exqlite.bind/3`, please use `bind/2` instead.
66
- changed: Improved multi-threaded access to underlying sqlite resource.
7+
- changed: Document issue with calling `close/1` immediately after calling
8+
`interrupt/1`. If you encounter the issue where the entire BEAM crashes, put
9+
a short sleep between the call to `interrupt/1` and `close/1`.
710

811
## v0.28.0
912

lib/exqlite/sqlite3.ex

+9
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,15 @@ defmodule Exqlite.Sqlite3 do
8686

8787
@doc """
8888
Interrupt a long-running query.
89+
90+
> #### Warning {: .warning}
91+
> If you are going to interrupt a long running process, it is unsafe to call
92+
> `close/1` immediately after. You run the risk of undefined behavior. This
93+
> is a limitation of the sqlite library itself. Please see the documentation
94+
> https://www.sqlite.org/c3ref/interrupt.html for more information.
95+
>
96+
> If close must be called after, it is best to put a short sleep in order to
97+
> let sqlite finish doing its book keeping.
8998
"""
9099
@spec interrupt(db() | nil) :: :ok | {:error, reason()}
91100
def interrupt(nil), do: :ok

test/exqlite/sqlite3_test.exs

+1-1
Original file line numberDiff line numberDiff line change
@@ -792,7 +792,7 @@ defmodule Exqlite.Sqlite3Test do
792792

793793
Process.sleep(100)
794794
:ok = Sqlite3.interrupt(conn)
795-
795+
Process.sleep(100)
796796
:ok = Sqlite3.close(conn)
797797
end
798798
end

0 commit comments

Comments
 (0)