Skip to content

Possible concurrency issues, using VST connection #86

Closed
@ewoutp

Description

@ewoutp

Reproduce using this code:

package main

import (
	"context"
	"crypto/tls"
	"fmt"
	"log"
	"sync"

	"github.com/arangodb/go-driver"
	"github.com/arangodb/go-driver/vst"
	"github.com/arangodb/go-driver/vst/protocol"
)

func createConnection() driver.Connection {
	endpoint := "vst://127.0.0.1:8529"
	config := vst.ConnectionConfig{
		Endpoints: []string{endpoint},
		Transport: protocol.TransportConfig{
			IdleConnTimeout: 0,
			Version:         protocol.Version1_1,
		},
	}

	conn, err := vst.NewConnection(config)

	if err != nil {
		panic(err)
	}

	return conn
}

func createClient() driver.Client {
	conn := createConnection()
	c, err := driver.NewClient(driver.ClientConfig{
		Connection: conn,
	})

	if err != nil {
		panic(err)
	}

	v, err := c.Version(nil)
	if err != nil {
		panic(err)
	}
	fmt.Printf("Version: %v\n", v)

	return c
}

func listAll(c driver.Client, page int) {
	ctx := context.Background()

	db, err := c.Database(ctx, "_system")
	if err != nil {
		panic(err)
	}

	limit := 100
	aql := fmt.Sprintf("FOR v IN Foo LIMIT %d, %d RETURN v", page, limit)
	ctx = driver.WithQueryBatchSize(ctx, 100)
	listAllCursor, err := db.Query(ctx, aql, nil)
	if err != nil {
		panic(err)
	}
	defer listAllCursor.Close()

	for listAllCursor.HasMore() {
		var ent map[string]interface{}
		if _, err := listAllCursor.ReadDocument(ctx, &ent); err != nil {
			panic(err)
		}
	}
}

func main() {
	c := createClient()

	wg := sync.WaitGroup{}
	for i := 0; i < 1000; i++ {
		wg.Add(1)
		go func(i int) {
			defer wg.Done()

			for x := 0; x < 5; x++ {
				log.Printf("i=%d, x=%d\n", i, x)
				listAll(c, i)
			}
		}(i)
	}
	wg.Wait()
}

To run, initialise a Foo collection in _system database with this query:

FOR i IN 0..100000 
INSERT { x:i, foo1:"hello",foo2:"bar", foo3:"void", foo4:true} INTO Foo

It has been seen to fail with these errors:

Nil-reference:

context.(*timerCtx).Value(0xc420625da0, 0x699680, 0x73ae90, 0xc4293a9740, 0x2)

        <autogenerated>:1 +0x32

github.com/arangodb/go-driver/vst.(*vstConnection).do(0xc420114000, 0x85fcc0, 0xc420625da0, 0x861480, 0xc420a74870, 0x85bb40, 0xc42008c370, 0x893c20, 0x85fcc0, 0xc420625da0, ...)

        /src/github.com/arangodb/go-driver/vst/connection.go:170 +0x48c

github.com/arangodb/go-driver/vst.(*vstConnection).Do(0xc420114000, 0x85fcc0, 0xc420625da0, 0x861480, 0xc420a74870, 0xc4236424f0, 0x0, 0xc420472300, 0x718228)

        /src/github.com/arangodb/go-driver/vst/connection.go:136 +0x75

github.com/arangodb/go-driver/cluster.(*clusterConnection).Do(0xc420110000, 0x85fd00, 0xc4293a96b0, 0x861480, 0xc420a74870, 0xc420a74870, 0x0, 0x0, 0x0)

        /src/github.com/arangodb/go-driver/cluster/cluster.go:142 +0x249

github.com/arangodb/go-driver.(*database).Query(0xc422b8ec20, 0x85fd00, 0xc4293a96b0, 0xc42c206510, 0x25, 0x0, 0x25, 0x0, 0x0, 0xb)

        /src/github.com/arangodb/go-driver/database_impl.go:121 +0x295

Send on closed channel

github.com/arangodb/go-driver/vst/protocol.(*Connection).processChunk(0xc4200fe070, 0x6, 0x437, 0x20470, 0xc4277b8000, 0x77f0, 0x77f0)

        /src/github.com/arangodb/go-driver/vst/protocol/connection.go:256 +0x1a6

created by github.com/arangodb/go-driver/vst/protocol.(*Connection).readChunkLoop

        /src/github.com/arangodb/go-driver/vst/protocol/connection.go:229 +0x29d

Errors we're caught on linux with ArangoDB 3.2.9

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions