go-driver
go-driver copied to clipboard
Add active Close method.
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
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.
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.
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?
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.
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.
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
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.