Make ping timeout configurable (fixes #1751)

This commit is contained in:
Audrius Butkevicius 2015-06-27 12:34:41 +01:00
parent 6cc7f70a65
commit 93ad803073
6 changed files with 19 additions and 8 deletions

2
Godeps/Godeps.json generated
View File

@ -35,7 +35,7 @@
}, },
{ {
"ImportPath": "github.com/syncthing/protocol", "ImportPath": "github.com/syncthing/protocol",
"Rev": "e19e2c123e520d68b919740731140faee950e69d" "Rev": "9f871a372629080e07662db3ccf4f075bdac7a6f"
}, },
{ {
"ImportPath": "github.com/syndtr/goleveldb/leveldb", "ImportPath": "github.com/syndtr/goleveldb/leveldb",

View File

@ -140,9 +140,9 @@ type isEofer interface {
IsEOF() bool IsEOF() bool
} }
const ( var (
pingTimeout = 30 * time.Second PingTimeout = 30 * time.Second
pingIdleTime = 60 * time.Second PingIdleTime = 60 * time.Second
) )
func NewConnection(deviceID DeviceID, reader io.Reader, writer io.Writer, receiver Model, name string, compress Compression) Connection { func NewConnection(deviceID DeviceID, reader io.Reader, writer io.Writer, receiver Model, name string, compress Compression) Connection {
@ -684,17 +684,17 @@ func (c *rawConnection) idGenerator() {
func (c *rawConnection) pingerLoop() { func (c *rawConnection) pingerLoop() {
var rc = make(chan bool, 1) var rc = make(chan bool, 1)
ticker := time.Tick(pingIdleTime / 2) ticker := time.Tick(PingIdleTime / 2)
for { for {
select { select {
case <-ticker: case <-ticker:
if d := time.Since(c.cr.Last()); d < pingIdleTime { if d := time.Since(c.cr.Last()); d < PingIdleTime {
if debug { if debug {
l.Debugln(c.id, "ping skipped after rd", d) l.Debugln(c.id, "ping skipped after rd", d)
} }
continue continue
} }
if d := time.Since(c.cw.Last()); d < pingIdleTime { if d := time.Since(c.cw.Last()); d < PingIdleTime {
if debug { if debug {
l.Debugln(c.id, "ping skipped after wr", d) l.Debugln(c.id, "ping skipped after wr", d)
} }
@ -714,7 +714,7 @@ func (c *rawConnection) pingerLoop() {
if !ok { if !ok {
c.close(fmt.Errorf("ping failure")) c.close(fmt.Errorf("ping failure"))
} }
case <-time.After(pingTimeout): case <-time.After(PingTimeout):
c.close(fmt.Errorf("ping timeout")) c.close(fmt.Errorf("ping timeout"))
case <-c.closed: case <-c.closed:
return return

View File

@ -565,6 +565,9 @@ func syncthingMain() {
symlinks.Supported = false symlinks.Supported = false
} }
protocol.PingTimeout = time.Duration(opts.PingTimeoutS) * time.Second
protocol.PingIdleTime = time.Duration(opts.PingIdleTimeS) * time.Second
if opts.MaxSendKbps > 0 { if opts.MaxSendKbps > 0 {
writeRateLimit = ratelimit.NewBucketWithRate(float64(1000*opts.MaxSendKbps), int64(5*1000*opts.MaxSendKbps)) writeRateLimit = ratelimit.NewBucketWithRate(float64(1000*opts.MaxSendKbps), int64(5*1000*opts.MaxSendKbps))
} }

View File

@ -237,6 +237,8 @@ type OptionsConfiguration struct {
SymlinksEnabled bool `xml:"symlinksEnabled" json:"symlinksEnabled" default:"true"` SymlinksEnabled bool `xml:"symlinksEnabled" json:"symlinksEnabled" default:"true"`
LimitBandwidthInLan bool `xml:"limitBandwidthInLan" json:"limitBandwidthInLan" default:"false"` LimitBandwidthInLan bool `xml:"limitBandwidthInLan" json:"limitBandwidthInLan" default:"false"`
DatabaseBlockCacheMiB int `xml:"databaseBlockCacheMiB" json:"databaseBlockCacheMiB" default:"0"` DatabaseBlockCacheMiB int `xml:"databaseBlockCacheMiB" json:"databaseBlockCacheMiB" default:"0"`
PingTimeoutS int `xml:"pingTimeoutS" json:"pingTimeoutS" default:"30"`
PingIdleTimeS int `xml:"pingIdleTimeS" json:"pingIdleTimeS" default:"60"`
} }
func (orig OptionsConfiguration) Copy() OptionsConfiguration { func (orig OptionsConfiguration) Copy() OptionsConfiguration {

View File

@ -53,6 +53,8 @@ func TestDefaultValues(t *testing.T) {
SymlinksEnabled: true, SymlinksEnabled: true,
LimitBandwidthInLan: false, LimitBandwidthInLan: false,
DatabaseBlockCacheMiB: 0, DatabaseBlockCacheMiB: 0,
PingTimeoutS: 30,
PingIdleTimeS: 60,
} }
cfg := New(device1) cfg := New(device1)
@ -160,6 +162,8 @@ func TestOverriddenValues(t *testing.T) {
SymlinksEnabled: false, SymlinksEnabled: false,
LimitBandwidthInLan: true, LimitBandwidthInLan: true,
DatabaseBlockCacheMiB: 42, DatabaseBlockCacheMiB: 42,
PingTimeoutS: 60,
PingIdleTimeS: 120,
} }
cfg, err := Load("testdata/overridenvalues.xml", device1) cfg, err := Load("testdata/overridenvalues.xml", device1)

View File

@ -24,5 +24,7 @@
<symlinksEnabled>false</symlinksEnabled> <symlinksEnabled>false</symlinksEnabled>
<limitBandwidthInLan>true</limitBandwidthInLan> <limitBandwidthInLan>true</limitBandwidthInLan>
<databaseBlockCacheMiB>42</databaseBlockCacheMiB> <databaseBlockCacheMiB>42</databaseBlockCacheMiB>
<pingTimeoutS>60</pingTimeoutS>
<pingIdleTimeS>120</pingIdleTimeS>
</options> </options>
</configuration> </configuration>