PatrickJS/angular-websocket

Question on reconnection

bastbnl opened this issue · 3 comments

Thanks for building and maintaining angular-websocket! It really saves a bunch of work and it works nicely.

I do have a question regarding reconnection:
if (this.reconnectIfNotNormalClose && event.code !== this._normalCloseCode || this._reconnectableStatusCodes.indexOf(event.code) > -1) {

What is the intention here? Should it evaluate to:
(this.reconnectIfNotNormalClose && event.code !== this._normalCloseCode) || this._reconnectableStatusCodes.indexOf(event.code) > -1)

or
this.reconnectIfNotNormalClose && (event.code !== this._normalCloseCode || this._reconnectableStatusCodes.indexOf(event.code) > -1)

I'm asking, because I'm using version 2.0 in a project and I can see the code reconnecting while closing the connection using code 1011.

The code for a normal closure is 1000. So, it's working as intended if it's reconnecting for code 1011.

Since && has a higher precedence than ||, the code is equivalent to your first example: (this.reconnectIfNotNormalClose && event.code !== this._normalCloseCode) || this._reconnectableStatusCodes.indexOf(event.code) > -1

Since I'm the one who added the reconnectIfNotNormalClose flag, I'll take a minute to explain. Before I added that flag, the only option for reconnecting was to add your codes to the reconnectableStatusCodes array (basically a whitelist).

Well, I didn't want to add every single code except 1000 to that list. So I took the approach, where if you enable the reconnectIfNotNormalClose flag, then the websocket will reconnect for everything except 1000, which is the normal (i.e. "I meant to close it") code.

Thank you for explaining battmanz. I'm using your contribution on channels with Django 1.10 and I'm noticing reconnects, even when I'm closing with code 1000. At least, that's in the code I use to close the channel. I didn't verify the return code within the WebSocket module yet and I'll do that later on.

I'll submit a PR containing the grouping as I believe it makes things more obvious. I'm oldskool ;-)

Just verified; channels is closing the connection using code 1005 (CLOSE_NO_STATUS). The module is trying to reconnect, which makes the server continuously close the connection. So I'll have to find a solution.

I'll raise an issue on channels, trying to see if I can find a solution there. Thanks for your help