sv / kdbgo

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

panic: github.com/sv/kdbgo/kdb.go:85 +0x179 #5

Closed a7a2 closed 6 years ago

a7a2 commented 6 years ago

panic: runtime error: slice bounds out of range

goroutine 162 [running]: bufio.(Reader).Read(0xc4202181e0, 0xc4216b5c88, 0x8, 0x8, 0x8, 0x16c96e0, 0x0) /usr/local/go/src/bufio/bufio.go:227 +0x3bf io.ReadAtLeast(0x1888be0, 0xc4202181e0, 0xc4216b5c88, 0x8, 0x8, 0x8, 0x16c9760, 0x1767701, 0xc4216b5c88) /usr/local/go/src/io/io.go:309 +0x86 io.ReadFull(0x1888be0, 0xc4202181e0, 0xc4216b5c88, 0x8, 0x8, 0x8, 0xc420036f00, 0xc420070218) /usr/local/go/src/io/io.go:327 +0x58 encoding/binary.Read(0x1888be0, 0xc4202181e0, 0x1890300, 0x1cb5b00, 0x1708000, 0xc4216b5348, 0xc420704380, 0xc4216efad0) /usr/local/go/src/encoding/binary/binary.go:245 +0xf48 github.com/sv/kdbgo.Decode(0xc4202181e0, 0xc420222028, 0x1, 0xc421213f40, 0x0) /github.com/sv/kdbgo/decode.go:141 +0x95 github.com/sv/kdbgo.(KDBConn).Call(0xc4201e2230, 0xc424473dc0, 0x3d, 0x0, 0x0, 0x0, 0xc42000e018, 0xc420e1bed8, 0x1) /github.com/sv/kdbgo/kdb.go:85 +0x179

sv commented 6 years ago

do you have reproducer? which version of kdbgo, go, kdb+ is that?

a7a2 commented 6 years ago

go version go1.10 darwin/amd64. KDB+ 3.5.

maybe no header,I call like this: _, err = conn.Call("data insert (2018.04.04T21:17:48z;`AUS200;5721e;5725.1e)")

and sometimes get error like this: "kdb+ Query failed: header is invalid data insert (2018.04.04T21:17:48z;AUS200;5721e;5725.1e)"

So sorry that my poor english,high speed address operation recommended lock(package sync). Add sync.Mutex in github.com/sv/kdbgo/kdb.go:85 +0x179: sLock.Lock() defer sLock.Unlock() data, _, err = Decode(c.rbuf)

No any error now.thanks

sv commented 6 years ago

What was the issue?

On Wed, 4 Apr 2018, 3:32 pm 康生, notifications@github.com wrote:

Closed #5 https://github.com/sv/kdbgo/issues/5.

— You are receiving this because you commented.

Reply to this email directly, view it on GitHub https://github.com/sv/kdbgo/issues/5#event-1556614867, or mute the thread https://github.com/notifications/unsubscribe-auth/AAA3BqaRPVt_Z3SLLYAsYyGuvB3xpSVMks5tlNllgaJpZM4TGvNQ .

a7a2 commented 6 years ago

reproducer: `package main

import ( "fmt"

"github.com/sv/kdbgo"

)

var conn *kdb.KDBConn

func init() { var err error conn, err = kdb.DialKDB("127.0.0.1", 9999, "") if err != nil { fmt.Println("Failed to connect:", err) return } _, err = conn.Call("data:([]date:datetime$();sym:symbol$();bid:real$();ask:real$())") if err != nil { fmt.Println("Query failed:", err) } }

func main() { for { go func() { res, err := conn.Call("data insert (2018.04.04T22:07:59z;XOM.NYSE;74e;74.01e)") if err != nil { fmt.Println("Query failed:", err) } fmt.Println("Result:", res) }() }

} `

sv commented 6 years ago

Is it still an issue? I see that you closed it now

On Wed, 4 Apr 2018, 3:59 pm 康生, notifications@github.com wrote:

reproducer: `package main

import ( "fmt"

"github.com/sv/kdbgo"

)

var conn *kdb.KDBConn

func init() { var err error conn, err = kdb.DialKDB("127.0.0.1", 9999, "") if err != nil { fmt.Println("Failed to connect:", err) return

} _, err = conn.Call("data:([]date:datetime$();sym:symbol$();bid: real$();ask:real$())")

if err != nil { fmt.Println("Query failed:", err) } }

func main() { for { go func() { res, err := conn.Call("data insert (2018.04.04T22:07:59z; XOM.NYSE;74e;74.01e)") if err != nil { fmt.Println("Query failed:", err) } fmt.Println("Result:", res) }() }

} `

— You are receiving this because you commented.

Reply to this email directly, view it on GitHub https://github.com/sv/kdbgo/issues/5#issuecomment-378631093, or mute the thread https://github.com/notifications/unsubscribe-auth/AAA3Bi7Ty09FLRio8FQZaO2JCqm0r2Jyks5tlN-ygaJpZM4TGvNQ .

a7a2 commented 6 years ago

I don't know much about the rules of the GitHub,temporary fix use by ‘sync.lock’。 I need to write code for my project, which will not waste too more time to understand it.

sv commented 6 years ago

I see. Why do you need to insert from infinite number of goroutines? It will be in random order anyway. It is not designed to be used that way - you can have finite number of goroutines(1000) each one with own connection. There is no internal queue of messages inside library

On Wed, 4 Apr 2018, 7:03 pm 康生, notifications@github.com wrote:

I don't know much about the rules of the GitHub,temporary fix use by ‘sync.lock’。 I need to write code for my project, which will not waste too more time to understand it.

— You are receiving this because you commented.

Reply to this email directly, view it on GitHub https://github.com/sv/kdbgo/issues/5#issuecomment-378691606, or mute the thread https://github.com/notifications/unsubscribe-auth/AAA3BrdO_W5G1jh0D6skow7Idusuz_HKks5tlQrXgaJpZM4TGvNQ .

a7a2 commented 6 years ago

I just recur the problem. In the actual project ,I just collect forex data to kdb+ and then expose this issue. There is a need to use ‘go’ in the actual project. For example:The kdb+ server is so far away and the network delay > 500ms,blocked network. Do not use channel to solve the problem as much as possible.

sv commented 6 years ago

You can use readers or writers only from one routine for each connection(although you can read from one routine and write from another async). Communicate by sharing the connection. This is an idiomatic way for go. a mutex in user code is fine, i.e. the way you solved it. otherwise, it becomes limiting if you have reader spinning on one goroutine and trying to make sync call from another...

On Wed, 4 Apr 2018 at 18:37 康生 notifications@github.com wrote:

I just recur the problem. In the actual project ,I just collect forex data to kdb+ and then expose this issue. There is a need to use ‘go’ in the actual project. For example:The kdb+ server is so far away and the network delay > 500ms,blocked network. Do not use channel to solve the problem as much as possible.

— You are receiving this because you commented.

Reply to this email directly, view it on GitHub https://github.com/sv/kdbgo/issues/5#issuecomment-378702170, or mute the thread https://github.com/notifications/unsubscribe-auth/AAA3BtydwySeNyEFHl6pSD8nUUMo45fJks5tlRLkgaJpZM4TGvNQ .