Skip to content

Commit 07f4211

Browse files
bors[bot]Thearasalallema
authored
Merge #303
303: Reduce the probability of connection reset r=alallema a=Thearas # Pull Request ## What does this PR do? Reduce the probability of issue #221 occurrence. For more info see the discussion at fasthttp: <valyala/fasthttp#1315 (comment)> ## PR checklist Please check if your PR fulfills the following requirements: - [x] Does this PR fix an existing issue? - [x] Have you read the contributing guidelines? - [x] Have you made sure that the title is accurate and descriptive of the changes? Thank you so much for contributing to Meilisearch! Co-authored-by: Thearas <thearas850@gmail.com> Co-authored-by: Amélie <alallema@users.noreply.github.com>
2 parents 4690cbb + 5960d12 commit 07f4211

File tree

4 files changed

+34
-1
lines changed

4 files changed

+34
-1
lines changed

client.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,8 @@ func NewFastHTTPCustomClient(config ClientConfig, client *fasthttp.Client) *Clie
7272
func NewClient(config ClientConfig) *Client {
7373
client := &fasthttp.Client{
7474
Name: "meilisearch-client",
75+
// Reuse the most recently-used idle connection.
76+
ConnPoolStrategy: fasthttp.LIFO,
7577
}
7678
c := &Client{
7779
config: config,

client_test.go

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package meilisearch
22

33
import (
44
"context"
5+
"sync"
56
"testing"
67
"time"
78

@@ -891,6 +892,29 @@ func TestClient_WaitForTaskWithContext(t *testing.T) {
891892
}
892893
}
893894

895+
func TestClient_ConnectionCloseByServer(t *testing.T) {
896+
t.Skip("Skip until <https://github.com/meilisearch/meilisearch/pull/2471> merged.")
897+
898+
meili := NewClient(ClientConfig{Host: "http://localhost:7700"})
899+
900+
// Simulate 10 clients sending requests.
901+
g := sync.WaitGroup{}
902+
for i := 0; i < 10; i++ {
903+
g.Add(1)
904+
go func() {
905+
defer g.Done()
906+
907+
_, _ = meili.Index("foo").Search("bar", &SearchRequest{})
908+
time.Sleep(5 * time.Second)
909+
_, err := meili.Index("foo").Search("bar", &SearchRequest{})
910+
if e, ok := err.(*Error); ok && e.ErrCode == MeilisearchCommunicationError {
911+
require.NoErrorf(t, e, "unexpected error")
912+
}
913+
}()
914+
}
915+
g.Wait()
916+
}
917+
894918
func TestClient_GenerateTenantToken(t *testing.T) {
895919
type args struct {
896920
UID string

go.mod

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,9 @@ go 1.16
44

55
require (
66
github.com/golang-jwt/jwt v3.2.2+incompatible
7+
github.com/klauspost/compress v1.15.6 // indirect
78
github.com/mailru/easyjson v0.7.7
89
github.com/pkg/errors v0.9.1
910
github.com/stretchr/testify v1.7.1
10-
github.com/valyala/fasthttp v1.36.0
11+
github.com/valyala/fasthttp v1.37.1-0.20220607072126-8a320890c08d
1112
)

go.sum

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ github.com/josharian/intern v1.0.0 h1:vlS4z54oSdjm0bgjRigI+G1HpF+tI+9rE5LLzOg8Hm
88
github.com/josharian/intern v1.0.0/go.mod h1:5DoeVV0s6jJacbCEi61lwdGj/aVlrQvzHFFd8Hwg//Y=
99
github.com/klauspost/compress v1.15.0 h1:xqfchp4whNFxn5A4XFyyYtitiWI8Hy5EW59jEwcyL6U=
1010
github.com/klauspost/compress v1.15.0/go.mod h1:/3/Vjq9QcHkK5uEr5lBEmyoZ1iFhe47etQ6QUkpK6sk=
11+
github.com/klauspost/compress v1.15.6 h1:6D9PcO8QWu0JyaQ2zUMmu16T1T+zjjEpP91guRsvDfY=
12+
github.com/klauspost/compress v1.15.6/go.mod h1:PhcZ0MbTNciWF3rruxRgKxI5NkcHHrHUDtV4Yw2GlzU=
1113
github.com/mailru/easyjson v0.7.7 h1:UGYAvKxe3sBsEDzO8ZeWOSlIQfWFlxbzLZe7hwFURr0=
1214
github.com/mailru/easyjson v0.7.7/go.mod h1:xzfreul335JAWq5oZzymOObrkdz5UnU4kGfJJLY9Nlc=
1315
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
@@ -21,6 +23,10 @@ github.com/valyala/bytebufferpool v1.0.0 h1:GqA5TC/0021Y/b9FG4Oi9Mr3q7XYx6Kllzaw
2123
github.com/valyala/bytebufferpool v1.0.0/go.mod h1:6bBcMArwyJ5K/AmCkWv1jt77kVWyCJ6HpOuEn7z0Csc=
2224
github.com/valyala/fasthttp v1.36.0 h1:NhqfO/cB7Ajn1czkKnWkMHyPYr5nyND14ZGPk23g0/c=
2325
github.com/valyala/fasthttp v1.36.0/go.mod h1:t/G+3rLek+CyY9bnIE+YlMRddxVAAGjhxndDB4i4C0I=
26+
github.com/valyala/fasthttp v1.37.0 h1:7WHCyI7EAkQMVmrfBhWTCOaeROb1aCBiTopx63LkMbE=
27+
github.com/valyala/fasthttp v1.37.0/go.mod h1:t/G+3rLek+CyY9bnIE+YlMRddxVAAGjhxndDB4i4C0I=
28+
github.com/valyala/fasthttp v1.37.1-0.20220607072126-8a320890c08d h1:xS9QTPgKl9ewGsAOPc+xW7DeStJDqYPfisDmeSCcbco=
29+
github.com/valyala/fasthttp v1.37.1-0.20220607072126-8a320890c08d/go.mod h1:t/G+3rLek+CyY9bnIE+YlMRddxVAAGjhxndDB4i4C0I=
2430
github.com/valyala/tcplisten v1.0.0/go.mod h1:T0xQ8SeCZGxckz9qRXTfG43PvQ/mcWh7FwZEA7Ioqkc=
2531
golang.org/x/crypto v0.0.0-20220214200702-86341886e292/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4=
2632
golang.org/x/net v0.0.0-20211112202133-69e39bad7dc2/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=

0 commit comments

Comments
 (0)