Cgo argument has Go pointer to Go pointer


package main

import (
    _ ""

func main(){
if err != nil{

defer db.Close()
db.Exec("DROP table byt1")
_,err=db.Query("create table byt1(name INT)")
if err != nil{

st1,err:=db.Prepare("select name from byt1 ORDER BY name DESC")
if err != nil{

st2,err:=db.Prepare("Insert into byt1(name) values(?)")
if err != nil{

for n := 1; n <= 3; n++ {
    if _, err := st2.Exec(n); err != nil {
        fmt.Println("insert(%d) = %v", n, err)

const nRuns = 10
ch := make(chan bool)
        for i := 0; i < nRuns; i++ {
                go func() {
                        defer func() {
                                ch <- true
                        for j := 0; j < 10; j++ {
                                count := 0
                                if err := st1.QueryRow().Scan(&count); err != nil && err != sql.ErrNoRows {
                                        fmt.Println("Query: %v", err)
                                if _, err := st2.Exec(rand.Intn(100)); err != nil {
                                       fmt.Println("Insert: %v", err)
        for i := 0; i < nRuns; i++ {


panic: runtime error: cgo argument has Go pointer to Go pointer

goroutine 16 [running]:, 0xc00005a3f8, 0xc000000004, 0xc00005a3d8, 0x4edfe0)
/home/rakhil/go/src/ +0x4c, 0xc00005a3f8, 0x4, 0xc00005a3d8, 0x0)
/home/rakhil/go/src/ +0x59*BufferLen).Bind(0xc00005a3d8, 0x10001, 0x0, 0x440004, 0xc00005a3f8, 0x4, 0x8, 0xc000010350)
/home/rakhil/go/src/ +0x62*BindableColumn).Bind(0xc00005a3c0, 0x10001, 0x0, 0xc00005a3c0, 0x0, 0x0)
/home/rakhil/go/src/ +0x6c*ODBCStmt).BindColumns(0xc000092140, 0x7d9de0, 0x0)
/home/rakhil/go/src/ +0x1eb*Stmt).Query(0xc00007e2d0, 0x7d9de0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0)
/home/rakhil/go/src/ +0xe5
database/sql.ctxDriverStmtQuery(0x513040, 0xc000016138, 0x513140, 0xc00007e2d0, 0x7d9de0, 0x0, 0x0, 0x0, 0x0, 0x0, …)
/work/rakhil/go/src/database/sql/ctxutil.go:94 +0x16b
database/sql.rowsiFromStatement(0x513040, 0xc000016138, 0x512f40, 0xc000010290, 0xc00005a240, 0x0, 0x0, 0x0, 0x0, 0x0, …)
/work/rakhil/go/src/database/sql/sql.go:2511 +0x159
database/sql.(*Stmt).QueryContext(0xc0000a6000, 0x513040, 0xc000016138, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0)
/work/rakhil/go/src/database/sql/sql.go:2463 +0x203
database/sql.(*Stmt).QueryRowContext(0xc0000a6000, 0x513040, 0xc000016138, 0x0, 0x0, 0x0, 0xc000016218)
/work/rakhil/go/src/database/sql/sql.go:2521 +0x6d
database/sql.(*Stmt).QueryRow(0xc0000a6000, 0x0, 0x0, 0x0, 0x0)
/work/rakhil/go/src/database/sql/sql.go:2540 +0x61
main.main.func1(0xc00001c2a0, 0xc0000a6000, 0xc0000a6090)
/home/rakhil/go/src/ +0xb4
created by main.main
/home/rakhil/go/src/ +0x472
exit status 2

Please don’t open more than one topic for the same issue. Also, remember to format your code properly to help with legibility. Refer to this post, or this one for more info.

I changed it and i will delete the other one. Can you explain me why this error occurs

Is this a valid statement in this database’s sql? In mysql would it have been

select count(*) from byt1 ORDER BY count DESC

to count the number of rows in the table and also it will just result in one value so it isn’t really sort it.

the select statement has been stated wrong.

select name from byt1 ORDER BY name DESC

It is working for windows when it comes to linux it is producing the error.

I came to know that the error is because of releasing the channel in the main routine before all child go routines are completed. I don’t know whether it is correct or wrong . If this is the error how to solve it.

Look up waitgroups. This is an easy way to wait for multiple go routines to finish. Something like this:

Either you know the number of go routines in forehand (n) and then you could call wg.Add(n) or otherwise does each go routine a wg.Add(1). Each go routine then wd.Done() then finsished. And the main routine uses wg.Wait() for all routines to finish.

when i do
export GODEBUG=cgocheck=0
it is working fine in linux . Is it ok to do like this or i have to do some thing.

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.