orangeforum
orangeforum copied to clipboard
Creating a group causes database to be locked
When I was trying out a build from the master branch, I ran into an issue where creating any group with any user caused the database to be locked and become unusable.
Steps to reproduce:
- Clone and build orangeforum from 'master' branch
- Create any type of user
- Log in and create a group
- Click the "Orange Forum" text in the top-left corner
Result:
Error scanning row, database is locked.
Here's the log:
2018/08/06 03:34:26 main.go:206: [INFO] Starting orangeforum at :9123
2018/08/06 03:35:01 db.go:109: [ERROR] Error scanning row: database is locked
2018/08/06 03:35:01 utils.go:72: [INFO] Recovered from panic: [ERROR] Error scanning row: database is locked
[INFO] Debug stack: goroutine 167 [running]:
runtime/debug.Stack(0xc42021f470, 0x93de20, 0xc42025e4d0)
/usr/lib/go-1.8/src/runtime/debug/stack.go:24 +0x79
github.com/s-gv/orangeforum/views.ErrServerHandler(0xc18740, 0xc4200fa620, 0xc42016cd00)
.//orangeforum/.go/src/github.com/s-gv/orangeforum/views/utils.go:72 +0x5a
panic(0x93de20, 0xc42025e4d0)
/usr/lib/go-1.8/src/runtime/panic.go:489 +0x2cf
log.Panicf(0x9de510, 0x1f, 0xc42021f5e0, 0x1, 0x1)
/usr/lib/go-1.8/src/log/log.go:329 +0xda
github.com/s-gv/orangeforum/models/db.(*Row).Scan(0xc4200e0e80, 0xc42021f640, 0x1, 0x1, 0x1, 0xc4200e0e80)
.//orangeforum/.go/src/github.com/s-gv/orangeforum/models/db/db.go:109 +0xcc
github.com/s-gv/orangeforum/models.Config(0x9d44f6, 0xe, 0xc42021f6f0, 0x65a3d0)
.//orangeforum/.go/src/github.com/s-gv/orangeforum/models/config.go:50 +0x130
github.com/s-gv/orangeforum/views.censor(0xc42025e3bc, 0x4, 0x3, 0x3)
.//orangeforum/.go/src/github.com/s-gv/orangeforum/views/utils.go:189 +0x3a
github.com/s-gv/orangeforum/views.glob..func13(0xc18740, 0xc4200fa620, 0xc42016cd00, 0xc420262000, 0x2c, 0x1, 0x1, 0xc420262030, 0x2c, 0x0, ...)
.//orangeforum/.go/src/github.com/s-gv/orangeforum/views/misc.go:37 +0x25f
github.com/s-gv/orangeforum/views.UA.func1(0xc18740, 0xc4200fa620, 0xc42016cd00)
.//orangeforum/.go/src/github.com/s-gv/orangeforum/views/utils.go:94 +0x15e
net/http.HandlerFunc.ServeHTTP(0xc42016f2c0, 0xc18740, 0xc4200fa620, 0xc42016cd00)
/usr/lib/go-1.8/src/net/http/server.go:1942 +0x44
net/http.(*ServeMux).ServeHTTP(0xc4201ae750, 0xc18740, 0xc4200fa620, 0xc42016cd00)
/usr/lib/go-1.8/src/net/http/server.go:2238 +0x130
net/http.serverHandler.ServeHTTP(0xc420020fd0, 0xc18740, 0xc4200fa620, 0xc42016cd00)
/usr/lib/go-1.8/src/net/http/server.go:2568 +0x92
net/http.(*conn).serve(0xc4200ed220, 0xc18e40, 0xc4202361c0)
/usr/lib/go-1.8/src/net/http/server.go:1825 +0x612
created by net/http.(*Server).Serve
/usr/lib/go-1.8/src/net/http/server.go:2668 +0x2ce
I haven't been able to reproduce this on my machine. Which OS did this problem occur on? Was this with sqlite3 or Postgres?
It was on Alpine linux, but also with -extldflags "-static", which turns out to have been the problem. So it's actually a non-issue.
This issue is being reproduced without any algs with official docker image.
~ $ orangeforum
2018/10/11 07:20:07 main.go:206: [INFO] Starting orangeforum at :9123
2018/10/11 07:20:11 db.go:78: [ERROR] Error making stmt: SELECT val FROM configs WHERE name=?;. Err msg: database is locked
2018/10/11 07:20:11 utils.go:72: [INFO] Recovered from panic: [ERROR] Error making stmt: SELECT val FROM configs WHERE name=?;. Err msg: database is locked
[INFO] Debug stack: goroutine 47 [running]:
runtime/debug.Stack(0xc42005f490, 0x5646477d0a20, 0xc420216bd0)
/usr/lib/go/src/runtime/debug/stack.go:24 +0xa9
github.com/s-gv/orangeforum/views.ErrServerHandler(0x56464786fd00, 0xc420246000, 0xc42020b200)
/root/go/src/github.com/s-gv/orangeforum/views/utils.go:72 +0x5c
panic(0x5646477d0a20, 0xc420216bd0)
/usr/lib/go/src/runtime/panic.go:502 +0x22d
log.Panicf(0x5646474a128f, 0x2b, 0xc42005f620, 0x2, 0x2)
/usr/lib/go/src/log/log.go:333 +0xdc
github.com/s-gv/orangeforum/models/db.makeStmt(0x56464749e07d, 0x25, 0xc42005f690)
/root/go/src/github.com/s-gv/orangeforum/models/db/db.go:78 +0x17e
github.com/s-gv/orangeforum/models/db.QueryRow(0x56464749e07d, 0x25, 0xc42005f700, 0x1, 0x1, 0x20)
/root/go/src/github.com/s-gv/orangeforum/models/db/db.go:88 +0x3b
github.com/s-gv/orangeforum/models.Config(0x564647490b52, 0xe, 0xc42005f790, 0x564647346532)
/root/go/src/github.com/s-gv/orangeforum/models/config.go:48 +0xa8
github.com/s-gv/orangeforum/views.censor(0xc4200255d0, 0xc, 0x3, 0x3)
/root/go/src/github.com/s-gv/orangeforum/views/utils.go:189 +0x3c
github.com/s-gv/orangeforum/views.glob..func13(0x56464786fd00, 0xc420246000, 0xc42020b200, 0xc42017aae0, 0x2c, 0x1, 0x1, 0xc42017ab10, 0x2c, 0x0, ...)
/root/go/src/github.com/s-gv/orangeforum/views/misc.go:37 +0x26a
github.com/s-gv/orangeforum/views.UA.func1(0x56464786fd00, 0xc420246000, 0xc42020b200)
/root/go/src/github.com/s-gv/orangeforum/views/utils.go:94 +0x147
net/http.HandlerFunc.ServeHTTP(0xc420205760, 0x56464786fd00, 0xc420246000, 0xc42020b200)
/usr/lib/go/src/net/http/server.go:1947 +0x46
net/http.(*ServeMux).ServeHTTP(0xc420234060, 0x56464786fd00, 0xc420246000, 0xc42020b200)
/usr/lib/go/src/net/http/server.go:2337 +0x132
net/http.serverHandler.ServeHTTP(0xc4201ef5f0, 0x56464786fd00, 0xc420246000, 0xc42020b200)
/usr/lib/go/src/net/http/server.go:2694 +0xbe
net/http.(*conn).serve(0xc4200a97c0, 0x564647870080, 0xc42021f680)
/usr/lib/go/src/net/http/server.go:1830 +0x653
created by net/http.(*Server).Serve
/usr/lib/go/src/net/http/server.go:2795 +0x27d
Is that with sqlite or postgres?
@s-gv using sqlite
Throwing darts here.
-
Could be related to this: https://github.com/mattn/go-sqlite3/issues/274 Can you try removing the
github.com/mattn/go-sqlite3
package and installing the gcc version withgo install github.com/mattn/go-sqlite3
? -
Does it happen with GOMAXPROCS=1 environment variable?
Just ran a fresh copy and started working on this. Setting GOMAXPROCS=1 has no effect on it, nor does go install github.com/mattn/go-sqlite3.
I can confirm it sometimes (not always) also gets locked on Windows. Again GOMAXPROCS=1 and reinstalling sqlite does not have an effect.
I built from source and I'm getting this crash (create group, and crash will occur when I attempt to create new topic):
2019/01/19 10:46:38 main.go:206: [INFO] Starting orangeforum at :9123
2019/01/19 10:47:18 db.go:109: [ERROR] Error scanning row: database is locked
2019/01/19 10:47:18 utils.go:72: [INFO] Recovered from panic: [ERROR] Error scanning row: database is locked
Can you try adding db.SetMaxOpenConns(1)
to db.go
when using sqlite?
if driverName == "sqlite3" {
db.SetMaxOpenConns(1)
db.Exec("PRAGMA journal_mode = WAL;")
db.Exec("PRAGMA synchronous = FULL;")
db.Exec("PRAGMA foreign_keys = ON;")
}
This "fixes" crash, but it seems that server is deadlocked afterwards. Instead of crashing after clicking "Create" button, browser is now "Waiting for localhost..."
Can you identify which handler is hanging? Does TopicCreateHandler
return? Or is it GroupIndexHandler
that's hanging?
Also, does setting journal_mode
for sqlite in db.go
to DELETE
or OFF
help? (Without db.SetMaxOpenConns(1)
).
journal_mode=OFF fixed it
if driverName == "sqlite3" {
db.Exec("PRAGMA journal_mode = OFF;")
db.Exec("PRAGMA synchronous = FULL;")
db.Exec("PRAGMA foreign_keys = ON;")
}