Close internal Pipes in websocketconn.Conn Close.

Unless something externally called Write after Close, the
writeLoop(ws, pr2) goroutine would run forever, because nothing would
ever close pw2/pr2.
https://bugs.torproject.org/33367#comment:4
This commit is contained in:
David Fifield 2020-02-18 14:10:47 -07:00
parent 1220853a67
commit 380b133155
2 changed files with 30 additions and 0 deletions

View file

@ -24,6 +24,8 @@ func (conn *Conn) Write(b []byte) (n int, err error) {
}
func (conn *Conn) Close() error {
conn.Reader.(*io.PipeReader).Close()
conn.Writer.(*io.PipeWriter).Close()
// Ignore any error in trying to write a Close frame.
_ = conn.Conn.WriteControl(websocket.CloseMessage, []byte{}, time.Now().Add(time.Second))
return conn.Conn.Close()