Skip to content

Commit

Permalink
Merge #303
Browse files Browse the repository at this point in the history
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 <[email protected]>
Co-authored-by: Amélie <[email protected]>
  • Loading branch information
3 people authored Jun 7, 2022
2 parents 4690cbb + 5960d12 commit 07f4211
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 1 deletion.
2 changes: 2 additions & 0 deletions client.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,8 @@ func NewFastHTTPCustomClient(config ClientConfig, client *fasthttp.Client) *Clie
func NewClient(config ClientConfig) *Client {
client := &fasthttp.Client{
Name: "meilisearch-client",
// Reuse the most recently-used idle connection.
ConnPoolStrategy: fasthttp.LIFO,
}
c := &Client{
config: config,
Expand Down
24 changes: 24 additions & 0 deletions client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package meilisearch

import (
"context"
"sync"
"testing"
"time"

Expand Down Expand Up @@ -891,6 +892,29 @@ func TestClient_WaitForTaskWithContext(t *testing.T) {
}
}

func TestClient_ConnectionCloseByServer(t *testing.T) {
t.Skip("Skip until <https://github.com/meilisearch/meilisearch/pull/2471> merged.")

meili := NewClient(ClientConfig{Host: "http://localhost:7700"})

// Simulate 10 clients sending requests.
g := sync.WaitGroup{}
for i := 0; i < 10; i++ {
g.Add(1)
go func() {
defer g.Done()

_, _ = meili.Index("foo").Search("bar", &SearchRequest{})
time.Sleep(5 * time.Second)
_, err := meili.Index("foo").Search("bar", &SearchRequest{})
if e, ok := err.(*Error); ok && e.ErrCode == MeilisearchCommunicationError {
require.NoErrorf(t, e, "unexpected error")
}
}()
}
g.Wait()
}

func TestClient_GenerateTenantToken(t *testing.T) {
type args struct {
UID string
Expand Down
3 changes: 2 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@ go 1.16

require (
github.com/golang-jwt/jwt v3.2.2+incompatible
github.com/klauspost/compress v1.15.6 // indirect
github.com/mailru/easyjson v0.7.7
github.com/pkg/errors v0.9.1
github.com/stretchr/testify v1.7.1
github.com/valyala/fasthttp v1.36.0
github.com/valyala/fasthttp v1.37.1-0.20220607072126-8a320890c08d
)
6 changes: 6 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ github.com/josharian/intern v1.0.0 h1:vlS4z54oSdjm0bgjRigI+G1HpF+tI+9rE5LLzOg8Hm
github.com/josharian/intern v1.0.0/go.mod h1:5DoeVV0s6jJacbCEi61lwdGj/aVlrQvzHFFd8Hwg//Y=
github.com/klauspost/compress v1.15.0 h1:xqfchp4whNFxn5A4XFyyYtitiWI8Hy5EW59jEwcyL6U=
github.com/klauspost/compress v1.15.0/go.mod h1:/3/Vjq9QcHkK5uEr5lBEmyoZ1iFhe47etQ6QUkpK6sk=
github.com/klauspost/compress v1.15.6 h1:6D9PcO8QWu0JyaQ2zUMmu16T1T+zjjEpP91guRsvDfY=
github.com/klauspost/compress v1.15.6/go.mod h1:PhcZ0MbTNciWF3rruxRgKxI5NkcHHrHUDtV4Yw2GlzU=
github.com/mailru/easyjson v0.7.7 h1:UGYAvKxe3sBsEDzO8ZeWOSlIQfWFlxbzLZe7hwFURr0=
github.com/mailru/easyjson v0.7.7/go.mod h1:xzfreul335JAWq5oZzymOObrkdz5UnU4kGfJJLY9Nlc=
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
Expand All @@ -21,6 +23,10 @@ github.com/valyala/bytebufferpool v1.0.0 h1:GqA5TC/0021Y/b9FG4Oi9Mr3q7XYx6Kllzaw
github.com/valyala/bytebufferpool v1.0.0/go.mod h1:6bBcMArwyJ5K/AmCkWv1jt77kVWyCJ6HpOuEn7z0Csc=
github.com/valyala/fasthttp v1.36.0 h1:NhqfO/cB7Ajn1czkKnWkMHyPYr5nyND14ZGPk23g0/c=
github.com/valyala/fasthttp v1.36.0/go.mod h1:t/G+3rLek+CyY9bnIE+YlMRddxVAAGjhxndDB4i4C0I=
github.com/valyala/fasthttp v1.37.0 h1:7WHCyI7EAkQMVmrfBhWTCOaeROb1aCBiTopx63LkMbE=
github.com/valyala/fasthttp v1.37.0/go.mod h1:t/G+3rLek+CyY9bnIE+YlMRddxVAAGjhxndDB4i4C0I=
github.com/valyala/fasthttp v1.37.1-0.20220607072126-8a320890c08d h1:xS9QTPgKl9ewGsAOPc+xW7DeStJDqYPfisDmeSCcbco=
github.com/valyala/fasthttp v1.37.1-0.20220607072126-8a320890c08d/go.mod h1:t/G+3rLek+CyY9bnIE+YlMRddxVAAGjhxndDB4i4C0I=
github.com/valyala/tcplisten v1.0.0/go.mod h1:T0xQ8SeCZGxckz9qRXTfG43PvQ/mcWh7FwZEA7Ioqkc=
golang.org/x/crypto v0.0.0-20220214200702-86341886e292/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4=
golang.org/x/net v0.0.0-20211112202133-69e39bad7dc2/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
Expand Down

0 comments on commit 07f4211

Please sign in to comment.