gocql icon indicating copy to clipboard operation
gocql copied to clipboard

Panic in gocql.marshalVarchar

Open YeminLi opened this issue 5 years ago • 8 comments

What version of Scylla or Cassandra are you using?

3.0.7-0.20190528.4c16c1fe1

What version of Gocql are you using?

commit id = "91173a01ffb95ef90b31335d5cfc83eeda502a33"

What did you do?

call gocql get to get item

What did you expect to see?

no panic

What did you see instead?

panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x0 pc=0x461d2c]
	goroutine 709566504 [running]:
project/vendor/github.com/gocql/gocql.marshalVarchar(0x1b2d820, 0xc65b38a140, 0x149f340, 0xc68f1ada90, 0x0, 0xc09e53ce00, 0xc40ac045b0, 0xc40b95d7f0, 0xc40b95d7f8)
    /home/user/go/src/project/vendor/github.com/gocql/gocql/marshal.go:214 +0x486
project/vendor/github.com/gocql/gocql.Marshal(0x1b2d820, 0xc65b38a140, 0x149f340, 0xc68f1ada90, 0x40e246, 0xc44a273bc0, 0x403b7f, 0xc40b95d940, 0xc40b95d880)
    /home/user/go/src/project/vendor/github.com/gocql/gocql/marshal.go:68 +0x3b0
project/vendor/github.com/gocql/gocql.createRoutingKey(0xc478e904b0, 0xc68f1adaa0, 0x1, 0x1, 0xcc, 0xc478e904b0, 0x0, 0x0, 0x40f930)
    /home/user/go/src/project/vendor/github.com/gocql/gocql/session.go:1732 +0xa7
project/vendor/github.com/gocql/gocql.(*Query).GetRoutingKey(0xc409867680, 0xc40b95d948, 0x4416f3, 0x149c9c0, 0xc06c0, 0x144f6c0)
    /home/user/go/src/project/vendor/github.com/gocql/gocql/session.go:991 +0xf7
project/vendor/github.com/gocql/gocql.(*tokenAwareHostPolicy).Pick(0xc06d59c690, 0x1b42ca0, 0xc409867680, 0xc40b95da90)
    /home/user/go/src/project/vendor/github.com/gocql/gocql/policies.go:591 +0x52
project/vendor/github.com/gocql/gocql.(*queryExecutor).do(0xc25968ea60, 0x1b2c860, 0xc4ab375c80, 0x1b42ca0, 0xc409867680, 0xb)
    /home/user/go/src/project/vendor/github.com/gocql/gocql/query_executor.go:87 +0x63
project/vendor/github.com/gocql/gocql.(*queryExecutor).executeQuery(0xc25968ea60, 0x1b42ca0, 0xc409867680, 0x0, 0x0, 0x0)
    /home/user/go/src/project/vendor/github.com/gocql/gocql/query_executor.go:60 +0x437
project/vendor/github.com/gocql/gocql.(*Session).executeQuery(0xc02c857c00, 0xc409867680, 0x17c3991)
    /home/user/go/src/project/vendor/github.com/gocql/gocql/session.go:407 +0xb7
project/vendor/github.com/gocql/gocql.(*Query).Iter(0xc409867680, 0x28)
    /home/user/go/src/project/vendor/github.com/gocql/gocql/session.go:1110 +0xa5
project/vendor/github.com/scylladb/gocqlx.Iter(...)
    /home/user/go/src/project/vendor/github.com/scylladb/gocqlx/iterx.go:46
project/vendor/github.com/scylladb/gocqlx.(*Queryx).Get(0xc40b95de20, 0x1593d20, 0xc40880a9a0, 0x179b3e0, 0xc02c857c00)
    /home/user/go/src/project/vendor/github.com/scylladb/gocqlx/queryx.go:212 +0x70
project/vendor/github.com/scylladb/gocqlx.(*Queryx).GetRelease(0xc40b95de20, 0x1593d20, 0xc40880a9a0, 0x0, 0x0)
    /home/user/go/src/project/vendor/github.com/scylladb/gocqlx/queryx.go:219 +0x84

If you are having connectivity related issues please share the following additional information

Describe your Cassandra cluster

please provide the following information

  • output of nodetool status
  • output of SELECT peer, rpc_address FROM system.peers
  • rebuild your application with the gocql_debug tag and post the output

YeminLi avatar Oct 24 '19 14:10 YeminLi

Hi, can you reproduce that? Can you reproduce that with the latest release 1.3.0?

mmatczuk avatar Oct 24 '19 18:10 mmatczuk

Hi, can you reproduce that? Can you reproduce that with the latest release 1.3.0?

Yes, it also happens. With either version, it's not often.

YeminLi avatar Oct 25 '19 19:10 YeminLi

What about with the latest 1.3.4?

I really have a very hard time getting how this could happen. Do you have a snippet of code and table structure that can reproduce this?

dahankzter avatar Apr 15 '20 08:04 dahankzter

Hi @YeminLi could you add information about Go version you use and what are you trying to marshal. A reproducer would be best. Thanks.

mmatczuk avatar Apr 15 '20 09:04 mmatczuk

reproducer of failing at []byte(s):

package main

import (
	"fmt"
	"reflect"
	"unsafe"
)

func f(value interface{}) []byte {
	switch v := value.(type) {
	case string:
		return []byte(v) // <-- panics here
	}
	return nil
}

func main() {
	var s = "b"
	(*reflect.StringHeader)(unsafe.Pointer(&s)).Data = 0
	fmt.Println(f(s))
}

$ go run main.go
panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x0 pc=0x45ccc2]

goroutine 1 [running]:
main.f(0x49fb20, 0xc000072f68, 0xc000072f48, 0x43dc7a, 0x54ee20)
	/home/sitano/Projects/siren/1/main.go:12 +0x80
main.main()
	/home/sitano/Projects/siren/1/main.go:20 +0x6c
exit status 2

the string is broken and runtime.stringtoslicebyte fails

sitano avatar Apr 15 '20 09:04 sitano

https://godbolt.org/z/N9cpt3 it can be seen that []byte(v) uses runtime function to convert from string

sitano avatar Apr 15 '20 09:04 sitano

Can you provide a small example where it happens using the driver @YeminLi?

dahankzter avatar Apr 23 '20 12:04 dahankzter

It happens when I'm doing a database read.

q := d.session.Query(getStmt).Consistency(gocql.One).Bind(key)
if err := gocqlx.Query(q, nil).WithContext(ctx).GetRelease(&object); err != nil {
    ...
}

Sorry I'm no able to provide any more useful information because it rarely happens and I don't see it happening recently...

YeminLi avatar Apr 23 '20 22:04 YeminLi