sv / kdbgo

kdb+ client driver for Go
MIT License
44 stars 29 forks source link

IPC Compression Implementation - Truncated Strings, Segmentation Fault #4

Closed mbalkanloo closed 6 years ago

mbalkanloo commented 6 years ago

I just started looking into this as I've been reaching a segmentation fault in kdb+ when passing strings over IPC (via AsyncCall, Call, and WriteMessage). The issue seems to lie in the Compress function which appears to truncate some input objects. When I remove compression from the Encode function, the object is sent as expected. I will upload more details later, but when I try passing several strings over IPC, each greater than 800 characters, I receive the seg fault in kdb+.

sv commented 6 years ago

Which version of kdb+ do you use? Can you provide small example which causes a crash?

mbalkanloo commented 6 years ago

32-bit free version of 3.5 released 2017.06.15. I will try to create an example that doesn't involve all of my feed handler code by tomorrow.

mbalkanloo commented 6 years ago

package main

import (
    "fmt"
    "log"
    "github.com/sv/kdbgo"
)

var addr, test string
var tests, port int

func init(){
    addr = "127.0.0.1"
    port = 7000
    tests = 4
    test = "20171130:1700-1515,1530-1600;20171201:1700-1515,1530-1600;20171202:1700-1515,1530-1600;20171203:CLOSED;20171204:CLOSED;20171205:1700-1515,1530-1600;20171206:1700-1515,1530-1600;20171207:1700-1515,1530-1600;20171208:1700-1515,1530-1600;20171209:1700-1515,1530-1600;20171210:CLOSED;20171211:CLOSED;20171212:1700-1515,1530-1600;20171213:1700-1515,1530-1600;20171214:1700-1515,1530-1600;20171215:1700-1515,1530-1600;20171216:1700-0830;20171217:CLOSED;20171218:CLOSED"
}

func main(){
    q, err := kdb.DialKDB(addr, port, "")
    if err != nil {
        log.Panic(err)
    }

    for i := 0; i < tests; i++ {
        err = sendTest(q, i, test)
        if err != nil {
            log.Panic(err)
        }
    }
}

func sendTest(q *kdb.KDBConn, name int, str string) error {
    fmt.Printf("length of test %d: %d\n", name, len(str))
    err := q.AsyncCall("upd", &kdb.K{kdb.KC, kdb.NONE, str})
    return err
}
mbalkanloo commented 6 years ago

Along with a simple upd function, the above code produces a seg fault for me. When I remove the Compress function from the Encode function, it works as expected.

sv commented 6 years ago

This should be fixed in now. Please try the latest version with go get -u

sv commented 6 years ago

In any case, kdb+ crash you experienced has been fixed in the more recent version of 3.5

mbalkanloo commented 6 years ago

Tested the new kdbgo code and I no longer receive any error and it works as expected. Thank you for fixing this so quickly.