ziutek / rrd

Bindings to rrdtool
Other
147 stars 44 forks source link

Calling Update results in Panic #27

Closed jinie closed 8 years ago

jinie commented 8 years ago

I'm not entirely sure this is an issue, or my wrong understanding on how to use the library. When i call Update(time.Now(),1234) i get a panic: panic: runtime error: cgo argument has Go pointer to Go pointer

Here's a snippet of my code:

u := rrd.NewUpdater(fname)
    tstamp, ok := time.Parse("2006-01-02 03:04:05.000000", timestamp)
    if ok != nil {
        Info.Println("Error parsing timestamp \"" + timestamp + "\"")
        tstamp = time.Now()
    }
    u.SetTemplate("a")
    err := u.Update(tstamp,reading)
    if err != nil {
        Error.Println(err)
    }

I've verified that the filename used to initialize the call to NewUpdater is in fact a string (and correct), and the types of the parameters in the call are time.Time and float64.

it appears to happen in the following code (src/github.com/ziutek/rrd/rrd_c.go:69 +0x100 github.com/ziutek/rrd.(*Updater).Update(0xc820129c38, 0x0, 0x0, 0x0, 0x0, 0x0))

func (u *Updater) update(args []unsafe.Pointer) error {
    e := C.rrdUpdate(
        (*C.char)(u.filename.p()),
        (*C.char)(u.template.p()),
        C.int(len(args)),
        (**C.char)(unsafe.Pointer(&args[0])),
    )
    return makeError(e)
}
ziutek commented 8 years ago

Confirm.

It is probably related to Go 1.6 "rules for sharing Go pointers with C code".

ziutek commented 8 years ago

Temporary solution:

GODEBUG=cgocheck=0

ziutek commented 8 years ago

Try last commit.

jinie commented 8 years ago

It seems to work here. The Update function is called, and nothing crashes.

22:29:46.177        func1 ▶ DEBUG  TOPIC: /surveillance/temperature/28-0314565062ff/fenrir
22:29:46.177        func1 ▶ DEBUG  MSG: {"reading":{"host":"fenrir","reading":2.625,"sensor":"28-0314565062ff","timestamp":"2016-02-22 22:29:46.070171"}}
22:29:46.177   GetRRDFile ▶ DEBUG  RRDFile: rrd/fenrir_28-0314565062ff.rrd
22:29:46.177    UpdateRRD ▶ DEBUG  Updating RRDFile: rrd/fenrir_28-0314565062ff.rrd , with values { fenrir , 28-0314565062ff , 2.625 , 2016-02-22 22:29:46.070171 }
ziutek commented 8 years ago

Ok. So close this issue.