Closed
Description
Greetings,
The documentation (and issue tracker, see #118) seems to imply that HTTP connections should be reused, but that doesn't seem to be the case. Here is a small app:
package main
import (
"context"
"fmt"
"log"
"strings"
"github.com/elastic/go-elasticsearch/v7"
"github.com/elastic/go-elasticsearch/v7/esapi"
)
func main() {
es, err := elasticsearch.NewClient(elasticsearch.Config{
Addresses: []string{"http://localhost:9200"},
//Transport: &http.Transport{MaxIdleConns: 8, MaxIdleConnsPerHost: 8, MaxConnsPerHost: 16, IdleConnTimeout: 10 * time.Second},
})
if err != nil {
panic(err)
}
for i := 0; i < 1000; i++ {
func() {
log.Printf("Saving %d\n", i)
req := esapi.IndexRequest{
Index: "test",
DocumentID: fmt.Sprintf("%d", i),
Body: strings.NewReader(`{}`),
Refresh: "true",
}
res, err := req.Do(context.Background(), es)
if err != nil {
log.Println(err)
}
defer func() {
err := res.Body.Close()
if err != nil {
log.Println(err)
}
}()
if res.IsError() {
log.Println(res.Status())
}
}()
}
}
Before running the app netstat -an | grep 9200
shows:
tcp4 0 0 127.0.0.1.9200 *.* LISTEN
tcp6 0 0 ::1.9200 *.* LISTEN
If I then execute netstat -an | grep 9200 | awk '{print $6}' | sort | uniq -c
while the app is running, the number of connections in TIME_WAIT state keeps growing. Running it immediately after the app finishes:
2 LISTEN
1000 TIME_WAIT
Reproduced on both linux and MacOS with Elasticsearch 7.5.1, go 1.13.6 and elastic/go-elasticsearch 7.5.0.
Many thanks,
damjan
Metadata
Metadata
Assignees
Labels
No labels