From 415d5fb4d0a265b8559d702305ba30da66f7ff3f Mon Sep 17 00:00:00 2001 From: Nickolai Zeldovich Date: Wed, 12 Jun 2019 12:59:09 -0400 Subject: [PATCH] websocket: terminate flushThread on Close() without writeTimeout --- Gopkg.lock | 4 ++-- vendor/github.com/algorand/websocket/.travis.yml | 1 + vendor/github.com/algorand/websocket/conn.go | 12 ++++++++++-- 3 files changed, 13 insertions(+), 4 deletions(-) diff --git a/Gopkg.lock b/Gopkg.lock index d3cc0fd5dd..5ef58f2560 100644 --- a/Gopkg.lock +++ b/Gopkg.lock @@ -21,11 +21,11 @@ [[projects]] branch = "master" - digest = "1:b9c9493bbc4f42ccf5cb7b28fe0303f236696820042180b7715a50f6e1457508" + digest = "1:8f6b71091c3cf5069b57669db97a79fb5939f82eae39f0d33cebb0496a8a1bb6" name = "github.com/algorand/websocket" packages = ["."] pruneopts = "UT" - revision = "a55d40ee35db4f6d093c397796790fe9dc1706a3" + revision = "8e576782c555b1e0edd8acb347649be04ff82d7f" [[projects]] digest = "1:f84c885bd17de475b92997e6e9972465e3c533894dd82223c0f62eda8852cc83" diff --git a/vendor/github.com/algorand/websocket/.travis.yml b/vendor/github.com/algorand/websocket/.travis.yml index 0212203dd9..a5021130cd 100644 --- a/vendor/github.com/algorand/websocket/.travis.yml +++ b/vendor/github.com/algorand/websocket/.travis.yml @@ -7,6 +7,7 @@ matrix: - go: 1.9.x - go: 1.10.x - go: 1.11.x + - go: 1.12.x - go: tip allow_failures: - go: tip diff --git a/vendor/github.com/algorand/websocket/conn.go b/vendor/github.com/algorand/websocket/conn.go index 60be513b62..90125afb3e 100644 --- a/vendor/github.com/algorand/websocket/conn.go +++ b/vendor/github.com/algorand/websocket/conn.go @@ -270,6 +270,7 @@ type Conn struct { bwPresent bool bwLock sync.Mutex bwCond sync.Cond + bwFlushClose chan struct{} readRemaining int64 // bytes remaining in current frame. readFinal bool // true the current message has more frames. readLength int64 // Message size. @@ -326,7 +327,10 @@ func newConn(conn net.Conn, isServer bool, readBufferSize, writeBufferSize int, compressionLevel: defaultCompressionLevel, } c.bwCond.L = &c.bwLock - go c.flushThread() + if c.bwPresent { + c.bwFlushClose = make(chan struct{}) + go c.flushThread() + } c.SetCloseHandler(nil) c.SetPingHandler(nil) c.SetPongHandler(nil) @@ -361,6 +365,7 @@ func (c *Conn) CloseWithoutFlush() error { c.bwLock.Lock() defer c.bwLock.Unlock() if c.bw != nil { + close(c.bwFlushClose) c.bw = nil } c.bwCond.Signal() @@ -471,7 +476,10 @@ func (c *Conn) flushThread() { c.bwLock.Unlock() bwTimeout.Reset(writeTimeout) - <-bwTimeout.C + select { + case <-bwTimeout.C: + case <-c.bwFlushClose: + } c.bwLock.Lock() if c.bw == nil {