go-driver icon indicating copy to clipboard operation
go-driver copied to clipboard

Add active Close method.

Open ashutosh-akss opened this issue 8 years ago • 4 comments

There is no way to close a connection and it's resulting in memory leak my 8gb RAM is filled within 1.5 minutes

Get http://localhost:8529/_db/redbus/_api/database/current: dial tcp 127.0.0.1:8529: connect: cannot assign requested address
panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x70 pc=0x4bc8be]

I am doing something like this

for _,item := range SomeArray{ ic:=getCount(item) }

func getCount(Item) (iCount int) {

conn, err := http.NewConnection(http.ConnectionConfig{
	Endpoints: []string{"http://localhost:8529"},
})
if err != nil {
	fmt.Println("Error in Arango Connection", err)
} else {
	// fmt.Println("Arangodb connection successfull")
}
c, err := driver.NewClient(driver.ClientConfig{
	Connection:     conn,
	Authentication: driver.BasicAuthentication("test", "test"),
})

if err != nil {
	fmt.Println("Error in Arango Client Creation", err)
} else {
	fmt.Println("Arangodb client creation successful")
}
db, err := c.Database(nil, "redbus")
if err != nil {
	fmt.Println("Error in database selection : ", err)
} else {
	fmt.Println("Selected Dataase ")
}
ctx := driver.WithQueryCount(context.Background())
query := `<some query to return count>`
cursor, err := db.Query(ctx, query, nil)
if err != nil {
	fmt.Println("ERROIR IN INTERLINKING COUNT CURSOR : ", err)
}
var interlinkingCount int
for {

	_, err := cursor.ReadDocument(ctx, &interlinkingCount)
	if driver.IsNoMoreDocuments(err) {
		fmt.Println("NO MORE INTERLINKIGN COUUNT DOCUMENTS : ", err)
		break
	} else if err != nil {
		fmt.Println(" Error in record interlinking count  : ", err)
	}

} /*for*/
defer cursor.Close()

return interlinkingCount

}

There is no way to close the connection object in this function resulting in leak

ashutosh-akss avatar Jun 18 '17 15:06 ashutosh-akss

Having a close makes a lot of sense.

Why do you make a new connection? You can also re-use the existing connection over and over again.

ewoutp avatar Jun 19 '17 06:06 ewoutp

Hi all, I stumbled upon the same question. Maybe it would be good to describe what "scope" driver.Client, driver.Database and driver.Collection belong to (if they are long living or short living objects). In my opinion that is not clearly described in the readme.

bitstorm-tech avatar Feb 02 '18 11:02 bitstorm-tech

Hi, any update on this issue? Because I'm using another library which depends on this driver. After doing some code-tracking, I believe if your arango client connection initialized by HTTP, there's no need to close the connection manually. Since the arango drive instance is a kind of HTTP client wrapper, when the query is executed, the connection will be closed by default. Here's the code: https://github.com/arangodb/go-driver/blob/17278d36b7e8d83b5d9bd26e9c3113803e4869a3/http/connection.go#L328 If no one uses the same HTTP client, Golang utilizes the garbage collection to release the memory. Therefore, will there be other scenarios that require the explicit Close method?

GoodVincentTu avatar Jan 15 '21 07:01 GoodVincentTu

There is no way to close a connection and it's resulting in memory leak my 8gb RAM is filled within 1.5 minutes

Get http://localhost:8529/_db/redbus/_api/database/current: dial tcp 127.0.0.1:8529: connect: cannot assign requested address
panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x70 pc=0x4bc8be]

I am doing something like this

for _,item := range SomeArray{ ic:=getCount(item) }

func getCount(Item) (iCount int) {

conn, err := http.NewConnection(http.ConnectionConfig{
	Endpoints: []string{"http://localhost:8529"},
})
if err != nil {
	fmt.Println("Error in Arango Connection", err)
} else {
	// fmt.Println("Arangodb connection successfull")
}
c, err := driver.NewClient(driver.ClientConfig{
	Connection:     conn,
	Authentication: driver.BasicAuthentication("test", "test"),
})

if err != nil {
	fmt.Println("Error in Arango Client Creation", err)
} else {
	fmt.Println("Arangodb client creation successful")
}
db, err := c.Database(nil, "redbus")
if err != nil {
	fmt.Println("Error in database selection : ", err)
} else {
	fmt.Println("Selected Dataase ")
}
ctx := driver.WithQueryCount(context.Background())
query := `<some query to return count>`
cursor, err := db.Query(ctx, query, nil)
if err != nil {
	fmt.Println("ERROIR IN INTERLINKING COUNT CURSOR : ", err)
}
var interlinkingCount int
for {

	_, err := cursor.ReadDocument(ctx, &interlinkingCount)
	if driver.IsNoMoreDocuments(err) {
		fmt.Println("NO MORE INTERLINKIGN COUUNT DOCUMENTS : ", err)
		break
	} else if err != nil {
		fmt.Println(" Error in record interlinking count  : ", err)
	}

} /*for*/
defer cursor.Close()

return interlinkingCount

}

There is no way to close the connection object in this function resulting in leak

Hi, it's a little bit late, however, I just check out your code again. Why did you do the query inside the for-loop instead of constructing your query params outside and batch get your information one time? If there are N objects in your SomeArray array, there'll be O(n) query to your DB requests, and I think that will greatly slow down the execution.

GoodVincentTu avatar Jan 15 '21 07:01 GoodVincentTu

Hi, I am a new user of ArangoDB driver, and I am surprised there is no a such method. I am writing a program that should be able to close a connection and because there is no Close() method, I do not know how to do.

charlyjna avatar Mar 21 '23 12:03 charlyjna

I don't think is needed. Arango works via HTTP REST APIs, so in theory, there is no connection to close. A connection is closed when the request is ended

antoniodipinto avatar Jul 19 '23 11:07 antoniodipinto

In Golang you can close a Connection only on the HTTP response level (resp.Body.Close()) which we already do. Hence there is no need to expose that on a high level.

jwierzbo avatar Jul 26 '23 13:07 jwierzbo