From 888369a0dd8a67933dc7f8fb1c58983cb4b2ac98 Mon Sep 17 00:00:00 2001 From: Steven Allen Date: Thu, 12 Mar 2020 21:33:55 -0700 Subject: [PATCH 1/3] chore: avoid leaking ping timers We wouldn't permanently leak them, but we'd leak them for the write timeout (10s). --- session.go | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/session.go b/session.go index 4f13814..abc16c9 100644 --- a/session.go +++ b/session.go @@ -304,9 +304,11 @@ func (s *Session) Ping() (time.Duration, error) { // Wait for a response start := time.Now() + timer := time.NewTimer(s.config.ConnectionWriteTimeout) + defer timer.Stop() select { case <-ch: - case <-time.After(s.config.ConnectionWriteTimeout): + case <-timer.C: s.pingLock.Lock() delete(s.pings, id) // Ignore it if a response comes later. s.pingLock.Unlock() @@ -316,7 +318,7 @@ func (s *Session) Ping() (time.Duration, error) { } // Compute the RTT - return time.Now().Sub(start), nil + return time.Since(start), nil } // startKeepalive starts the keepalive process. From bddc2944e4773b82cbdbba76d5cecb879eb2cfb4 Mon Sep 17 00:00:00 2001 From: Steven Allen Date: Thu, 12 Mar 2020 21:34:48 -0700 Subject: [PATCH 2/3] fix: don't keepalive when the connection is busy * It's a waste of bandwidth. * It causes us to think the connection is dead because the other side is too busy sending us _other_ data to respond to the ping. fixes #15 --- session.go | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/session.go b/session.go index abc16c9..42caeb3 100644 --- a/session.go +++ b/session.go @@ -508,6 +508,14 @@ func (s *Session) recvLoop() error { return err } + // Reset the keepalive timer every time we receive data. + // There's no reason to keepalive if we're active. Worse, if the + // peer is busy sending us stuff, the pong might get stuck + // behind a bunch of data. + if s.keepaliveTimer != nil { + s.keepaliveTimer.Reset(s.config.KeepAliveInterval) + } + // Verify the version if hdr.Version() != protoVersion { s.logger.Printf("[ERR] yamux: Invalid protocol version: %d", hdr.Version()) From 922d36fd64e5f1d6e2d4593ef9c3bfc1e4fa640d Mon Sep 17 00:00:00 2001 From: Steven Allen Date: Thu, 12 Mar 2020 21:39:08 -0700 Subject: [PATCH 3/3] ci: configure travis --- .travis.yml | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 .travis.yml diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..f912ec0 --- /dev/null +++ b/.travis.yml @@ -0,0 +1,29 @@ +os: + - linux + +language: go + +go: + - 1.14.x + +env: + global: + - GOTFLAGS="-race" + - BUILD_DEPTYPE=gomod + + +# disable travis install +install: + - true + +script: + - bash <(curl -s https://raw.githubusercontent.com/ipfs/ci-helpers/master/travis-ci/run-standard-tests.sh) + + +cache: + directories: + - $GOPATH/pkg/mod + - $HOME/.cache/go-build + +notifications: + email: false