Hello list,

It is about my (github-ed) monimelt <https://github.com/bstarynk/monimelt> 
(MELT monitor, in early pre-alpha stage) specifically about its commit 
44434cd991c 
<https://github.com/bstarynk/monimelt/commit/44434cd991c94fa6da831fb9e4292db476e22780>
 
which has some README.md 
<https://github.com/bstarynk/monimelt/blob/master/README.md> giving build 
instructions; I'm getting a reproducible bug that I don't understand, but I 
am still a newbie in Go.
I'm using go1.8 on Debian/Linux/Sid/x86-64 and I am building with gb 
<https://getgb.io/> (not with go build). The driving idea at first is to 
persist, in sqlite database using some JSON format, the entire heap -of 
some Scheme-like "interpreter"- made of "objects" or "items" and values.

To reproduce my bug, follow my build instructions (essentially, how to use 
gb to build my MELT monitor) then run

./bin/monimelt -final-dump-dir /tmp/mmmm


What should happen is that the /tmp/mmmm directory (of course you can 
replace that by any fresh path in /tmp or elsewhere) should be created and 
filled with two (almost empty) sqlite databases.
Actually I am creating temporary files in that directory, with some *random* 
suffix like e.g. +_9l7UhTyyJFx_p6950.tmp (of course when you'll run it 
you'll get *another* random suffix) and I want to rename these temporary 
files when at end of dump.


What is really happening is strange (and reproducible): 
2017/03/08 10:19:35 persist-init installed sqliteerrorlogmo
Monimelt starting pid 6950, Go version go1.8
2017/03/08 10:19:35 monimelt should final dump in /tmp/mmmm
2017/03/08 10:19:35 OpenDumperDirectory dirpath=/tmp/mmmm dtempsuf=+
_9l7UhTyyJFx_p6950.tmp
2017/03/08 10:19:35 create_table globflag=true dir=/tmp/mmmm
2017/03/08 10:19:35 create_table db=&{0xc420018530 file:/tmp/mmmm/
monimelt_state.sqlite+_9l7UhTyyJFx_p6950.tmp?mode=rwc&cache=private 0 {0 0} 
[] map[] 0 0 0xc420016480 false map[] map[] 0 0 0 <nil>} sql_create_t_params
="CREATE TABLE IF NOT EXISTS t_params \n (par_name VARCHAR(35) PRIMARY KEY 
ASC NOT NULL UNIQUE, \n  par_value TEXT NOT NULL);"
panic: runtime error: cgo argument has Go pointer to Go pointer

goroutine 1 [running]:
github.com/gwenn/gosqlite.(*Conn).ProgressHandler.func2(0x162b488, 
0xc400000064, 0xc42000c940)
    /home/basile/Documents/monimelt/vendor/src/github.com/gwenn/gosqlite/
trace.go:315 +0x8b
github.com/gwenn/gosqlite.(*Conn).ProgressHandler(0xc42009a640, 0x5833f8, 
0x100000000000064, 0x558460, 0xc420018440)
    /home/basile/Documents/monimelt/vendor/src/github.com/gwenn/gosqlite/
trace.go:316 +0x117
github.com/gwenn/gosqlite.(*conn).ExecContext(0xc42000e060, 0x8255e0, 
0xc420018440, 0x582e9f, 0x79, 0x851af8, 0x0, 0x0, 0x0, 0x0, ...)
    /home/basile/Documents/monimelt/vendor/src/github.com/gwenn/gosqlite/
driver.go:143 +0xcb
database/sql.ctxDriverExec(0x8255e0, 0xc420018440, 0x7fb37ce4e198, 
0xc42000e060, 0x582e9f, 0x79, 0x851af8, 0x0, 0x0, 0x42c0ae, ...)
    /usr/local/go/src/database/sql/ctxutil.go:31 +0x28d
database/sql.(*DB).exec.func2()
    /usr/local/go/src/database/sql/sql.go:1199 +0x99
database/sql.withLock(0x824ae0, 0xc42001a9a0, 0xc42004b6c0)
    /usr/local/go/src/database/sql/sql.go:2545 +0x65
database/sql.(*DB).exec(0xc42009a460, 0x8255e0, 0xc420018440, 0x582e9f, 0x79
, 0x0, 0x0, 0x0, 0x101, 0x0, ...)
    /usr/local/go/src/database/sql/sql.go:1200 +0x51c
database/sql.(*DB).ExecContext(0xc42009a460, 0x8255e0, 0xc420018440, 
0x582e9f, 0x79, 0x0, 0x0, 0x0, 0x145, 0x0, ...)
    /usr/local/go/src/database/sql/sql.go:1165 +0xbc
database/sql.(*DB).Exec(0xc42009a460, 0x582e9f, 0x79, 0x0, 0x0, 0x0, 0xa0, 
0xc42009a500, 0x0, 0x834a80)
    /usr/local/go/src/database/sql/sql.go:1179 +0x85
objvalmo.DumperMo.create_tables(0x0, 0x7ffc2316b893, 0x9, 0xc42000c900, 0x17
, 0xc42009a460, 0xc42009a500, 0x0, 0x0, 0x0, ...)
    /home/basile/Documents/monimelt/src/objvalmo/persist.go:208 +0x240
objvalmo.OpenDumperDirectory(0x7ffc2316b893, 0x9, 0x0)
    /home/basile/Documents/monimelt/src/objvalmo/persist.go:306 +0xb8b
objvalmo.DumpIntoDirectory(0x7ffc2316b893, 0x9)
    /home/basile/Documents/monimelt/src/objvalmo/persist.go:534 +0x39
main.main()
    /home/basile/Documents/monimelt/src/monimelt/monimelt.go:38 +0x8df


Now, here is my *partial* understanding of the issue.I suspect I have some 
bug in my code (but then I don't understand where), but it could be 
outside. Maybe it is related to the order of running the various init 
functions (and I don't understand that order, and I don't know how to order 
these initializations). Mayb the bug is elsewhere.

First, *I really need sqlite logging facilities*. So I need the C function 
sqlite3_config <http://sqlite.org/c3ref/config.html> to be called very 
early with SQLITE_CONFIG_LOG 
<http://sqlite.org/c3ref/c_config_covering_index_scan.html> and a function 
which justs log verbosely the error. The reason I need sqlite logging is 
that I sometimes am making stupid SQL mistakes, and that logging gives 
verbose enough messages to help me a lot.

So I have choosen gwenn's gosqlite implementation (on 
github.com/gwenn/gosqlite/ ; its README.md 
<https://github.com/gwenn/gosqlite/blob/master/README.md> mentions a caveat 
for Go1.6, perhaps related to my issue....; I'm using its latest commit 
5aa36f51eedd6425f99 
<https://github.com/gwenn/gosqlite/commit/5aa36f51eedd6425f9981324393f7251c915cf97>
 
from early march 2017) 
because it seems to be the only one intefacing that logging faciltity. 
Indeed, my src/objvalmo/persist.go 
<https://github.com/bstarynk/monimelt/blob/master/src/objvalmo/persist.go#L26> 
file has:
func sqliteerrorlogmo(d interface{}, err error, msg string) {
    log.Printf("SQLITE: %s, %s\n", err, msg)
}

func init() {
    err := gosqlite.ConfigLog(sqliteerrorlogmo, nil)
    if err != nil {
        panic(fmt.Errorf("persistmo could not ConfigLog sqlite: %v", err))
    }
    log.Printf("persist-init installed sqliteerrorlogmo\n")
}

and from the output I have shown before you see that this init is running 
(because of the persist-init output line) quite early.

My main function in src/monimelt/monimelt.go 
<https://github.com/bstarynk/monimelt/blob/master/src/monimelt/monimelt.go#L14> 
file is calling (in this example) my DumpIntoDirectory function in 
src/objvalmo/persist.go 
<https://github.com/bstarynk/monimelt/blob/master/src/objvalmo/persist.go#L532> 
file which calls the OpenDumperDirectory function 
<https://github.com/bstarynk/monimelt/blob/master/src/objvalmo/persist.go#L267> 
in the same file. That function is opening (for write, into a created 
temporary file) two sqlite databases (e.g. 
/tmp/mmmm/monimelt_state.sqlite+_9l7UhTyyJFx_p6950.tmp etc...). Then it 
create tables in both of them, using the create_tables function 
<https://github.com/bstarynk/monimelt/blob/master/src/objvalmo/persist.go#L196> 
in the same file, which calls Exec 
<https://github.com/bstarynk/monimelt/blob/master/src/objvalmo/persist.go#L208> 
(on databases, i.e. sql.DB <https://golang.org/pkg/database/sql/#DB.Exec>) 
with the CREATE TABLE IF NOT EXISTS t_params 
 (par_name VARCHAR(35) PRIMARY KEY ASC NOT NULL UNIQUE, par_value TEXT NOT 
NULL); SQL query stored in 
<https://github.com/bstarynk/monimelt/blob/master/src/objvalmo/persist.go#L177>
sql_create_t_param 
<https://github.com/bstarynk/monimelt/blob/master/src/objvalmo/persist.go#L177>
s constant. And that call to Exec is "panicking".

*I'm reluctant to disable some debugging facility* using the trick 
GODEBUG=cgocheck=0 mentioned by gwenn. I prefer possibly patch gwenn's code 
(and ideally, I would prefer that to happen, so that gosqlite remains 
usable with Go1.8). And it looks like the pull#268 
<https://github.com/mattn/go-sqlite3/pull/268> has been committed  in 
gosqlite.

So any help or advice are welcome. I'm ok with going into some other sqlite 
binding to go, provided I am able to SQLITE_CONFIG_LOG. FWIW, when coding 
in C, that is really simple 
<https://github.com/bstarynk/melt-monitor-2015/blob/expjs/main.c#L1671> for 
me.

Thanks for reading.


-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to