Files
mattermost/model
Agniva De Sarker 4f022aff6d MM-24547: Fix writer leak when connection closes (#14406)
* MM-24547: Fix writer leak when connection closes

When the connection is closed, the exit path does not
shut down the writer goroutine. In which case, it will keep spinning forever.

Since we already have the CAS mechanism now, we can move the closing
functionality into the main Close method and just call that in the defer block.

This makes closing the websocket client idempotent from both perspective -
- Explicitly closing.
- Closing due to connection tear down.

There are still 2 races left:
- Using the exported Conn to directly write messages. We cannot do anything about
that as long as clients directly using that.
- Setting the wsc.pingTimeoutTimer field in a separate goroutine when calling
.Connect(). This will need to be seen later.

* Fix ineffectual assignment

* Duplicate the closing of writer

The problem with refactoring the writer closing to a common
function was that we needed to wait for the reader to exit
before closing the EventChannel and ResponseChannel.

But then there is another problem that the API can be used in such
a way that the client is liable to call Close without even calling
Listen. In that case, we cannot wait for Listen to quit.

So from Close, we can only close the connection. And therefore
we need to duplicate the writer closing in the read loop's
defer block.

* Cleanup some comments
2020-04-30 23:50:13 +05:30
..
2020-04-07 15:22:54 +02:00