Emulating Multiple Requests To Sqlite Database As Goroutine Causes Random Panic
I am trying to emulate multiple requests from http.HandleFunc to function which makes changes to sqlite database. I assume that function which is called by http.HandleFunc is actua
Solution 1:
According to the documentation of the sqlite3 package, you should have one connection per goroutine and not a single connection shared by several goroutines.
From https://godoc.org/code.google.com/p/go-sqlite/go1/sqlite3:
Concurrency
A single connection instance and all of its derived objects (prepared statements, backup operations, etc.) may NOT be used concurrently from multiple goroutines without external synchronization. The only exception is Conn.Interrupt(), which may be called from another goroutine to abort a long-running operation. It is safe to use separate connection instances concurrently, even if they are accessing the same database file. For example:
// ERROR (without any extra synchronization) c, _ := sqlite3.Open("sqlite.db") go use(c) go use(c) // OK c1, _ := sqlite3.Open("sqlite.db") c2, _ := sqlite3.Open("sqlite.db") go use(c1) go use(c2)
Post a Comment for "Emulating Multiple Requests To Sqlite Database As Goroutine Causes Random Panic"