Skip to content

Commit e0bed3f

Browse files
committed
Do not send echo when inactivity check in progress
This commit skips spawning another goroutine to send echo when another echo check is already in progress. It also throws error if inactivity timeout value is lesser than reconnect timeout value while initializing client with WithInactivityCheck option. Signed-off-by: Periyasamy Palanisamy <[email protected]>
1 parent 49be92a commit e0bed3f

File tree

4 files changed

+21
-8
lines changed

4 files changed

+21
-8
lines changed

.github/workflows/ci.yml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,10 @@ jobs:
1212
runs-on: ubuntu-latest
1313
steps:
1414

15-
- name: Set up Go 1.18
16-
uses: actions/setup-go@v2
15+
- name: Set up Go 1.19.6
16+
uses: actions/setup-go@v3
1717
with:
18-
go-version: 1.18
18+
go-version: 1.19.6
1919
id: go
2020

2121
- name: Install benchstat
@@ -82,10 +82,10 @@ jobs:
8282
runs-on: ubuntu-latest
8383

8484
steps:
85-
- name: Set up Go 1.18
86-
uses: actions/setup-go@v1
85+
- name: Set up Go 1.19.6
86+
uses: actions/setup-go@v3
8787
with:
88-
go-version: 1.18
88+
go-version: 1.19.6
8989
id: go
9090

9191
- name: Check out code into the Go module directory

client/client.go

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import (
1313
"reflect"
1414
"strings"
1515
"sync"
16+
"sync/atomic"
1617
"time"
1718

1819
"github.com/cenkalti/backoff/v4"
@@ -1202,6 +1203,7 @@ func (o *ovsdbClient) handleInactivityProbes() {
12021203
stopCh := o.stopCh
12031204
trafficSeen := o.trafficSeen
12041205
timer := time.NewTimer(o.options.inactivityTimeout)
1206+
var echoInProgress atomic.Bool
12051207
for {
12061208
select {
12071209
case <-stopCh:
@@ -1212,15 +1214,22 @@ func (o *ovsdbClient) handleInactivityProbes() {
12121214
<-timer.C
12131215
}
12141216
case <-timer.C:
1215-
// Otherwise send an echo in a goroutine so that transactions don't block
1217+
// When echo request is already in the fly, ignore sending another
1218+
// echo message
1219+
if echoInProgress.Load() {
1220+
continue
1221+
}
1222+
// Send an echo in a goroutine so that transactions don't block
12161223
go func() {
1224+
echoInProgress.Store(true)
12171225
ctx, cancel := context.WithTimeout(context.Background(), o.options.timeout)
12181226
err := o.Echo(ctx)
12191227
if err != nil {
12201228
o.logger.V(3).Error(err, "server echo reply error")
12211229
o.Disconnect()
12221230
}
12231231
cancel()
1232+
echoInProgress.Store(false)
12241233
}()
12251234
}
12261235
timer.Reset(o.options.inactivityTimeout)

client/options.go

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

33
import (
44
"crypto/tls"
5+
"errors"
56
"net/url"
67
"time"
78

@@ -120,6 +121,9 @@ func WithReconnect(timeout time.Duration, backoff backoff.BackOff) Option {
120121
func WithInactivityCheck(inactivityTimeout, reconnectTimeout time.Duration,
121122
reconnectBackoff backoff.BackOff) Option {
122123
return func(o *options) error {
124+
if reconnectTimeout >= inactivityTimeout {
125+
return errors.New("inactivity timeout value should be greater than reconnect timeout value")
126+
}
123127
o.reconnect = true
124128
o.timeout = reconnectTimeout
125129
o.backoff = reconnectBackoff

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
module github.com/ovn-org/libovsdb
22

3-
go 1.18
3+
go 1.19
44

55
require (
66
github.com/cenkalti/backoff/v4 v4.1.3

0 commit comments

Comments
 (0)