Skip to content

Commit e1635f4

Browse files
committed
session: allow more attempts if bblfsh is reconnecting
Signed-off-by: Miguel Molina <[email protected]>
1 parent ede362b commit e1635f4

File tree

3 files changed

+6
-7
lines changed

3 files changed

+6
-7
lines changed

.travis.yml

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,10 @@ go:
55
- 1.9
66
- tip
77

8-
<<<<<<< HEAD
9-
go_import_path: github.com/src-d/gitbase
10-
=======
118
services:
129
- docker
1310

1411
go_import_path: github.com/src-d/gitbase
15-
>>>>>>> internal/function: implement uast and uast_xpath functions
1612

1713
matrix:
1814
fast_finish: true

internal/function/uast_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"context"
55
"testing"
66

7+
opentracing "github.com/opentracing/opentracing-go"
78
"github.com/src-d/gitbase"
89
"github.com/stretchr/testify/require"
910
"gopkg.in/bblfsh/client-go.v2/tools"
@@ -192,7 +193,7 @@ func setup(t *testing.T) (*sql.Context, func()) {
192193
}
193194

194195
session := gitbase.NewSession(&pool)
195-
ctx := sql.NewContext(context.TODO(), session)
196+
ctx := sql.NewContext(context.TODO(), session, opentracing.NoopTracer{})
196197

197198
return ctx, func() {
198199
require.NoError(t, fixtures.Clean())

session.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,16 +68,17 @@ func (s *Session) BblfshClient() (*bblfsh.Client, error) {
6868
}
6969
}
7070

71-
var attempts int
71+
var attempts, totalAttempts int
7272
for {
73-
if attempts > bblfshMaxAttempts {
73+
if attempts > bblfshMaxAttempts || totalAttempts > 3*bblfshMaxAttempts {
7474
return nil, ErrBblfshConnection.New()
7575
}
7676

7777
switch s.bblfshClient.GetState() {
7878
case connectivity.Ready, connectivity.Idle:
7979
return s.bblfshClient, nil
8080
case connectivity.Connecting:
81+
attempts = 0
8182
time.Sleep(100 * time.Millisecond)
8283
default:
8384
if err := s.bblfshClient.Close(); err != nil {
@@ -91,6 +92,7 @@ func (s *Session) BblfshClient() (*bblfsh.Client, error) {
9192
}
9293

9394
attempts++
95+
totalAttempts++
9496
}
9597
}
9698

0 commit comments

Comments
 (0)