pusher/libPusher

Explicit Disconnect causes reconnect

Opened this issue · 11 comments

Hey guys!

I wanted to implement some preferences to choose the apps that should be connected. By unchecking an app, the disconnection should happen. So I call the -(void) disconnect();-method, but the library throws an error via the delegate, that indicates a reconnect. And after the reconnectDelay, the client is being connected again. (iOS9)

That's not what you write into the header file, there you state, this would not happen. Maybe I use your library wrong?
I want an explicit disconnect without any reconnects.

screen shot 2015-11-05 at 21 35 24
screen shot 2015-11-05 at 21 35 11
(Calling my -(void) disconnect(); causes the delegate method in line 115 to be fired with willAttemptReconnect = YES)

Maybe you have an idea?

Thanks for the report, appears to be a dupe of #128 so it should be fixed but I will investigate.

In the meantime you can work around this by setting your own flag (e.g. shouldReconnect) before calling disconnect and if this is set to NO, returning NO from pusher:connectionWillAutomaticallyReconnect:afterDelay

Looking at the code, it will bypass automatic reconnection behaviour if you call disconnect and the Pusher connection disconnects with no error code. A normal disconnection shouldn't have an error code but its possible it is getting one after all, in which case it will interpret the Push error code according to the protocol guidelines and reconnect using an appropriate strategy.

Looks like I can add a further check in there so it doesn't do any error code handling at all if disconnect was called explicitly.

Oh, I did really some research but didn't see #128, sorry for this.

And I didn't know about pusher:connectionWillAutomaticallyReconnect:afterDelay, but with my own flag it works now.

BTW: Can you give some hints how to handle application transition with your library? Something like best practises? For example, I want automatic reconnects on applicationDidBecomeActive:. What do you recommend to do about application transition?

Thank you for your great library and support, I really like working with it.

Same thing happening to me. I've been tracking back the issue and I found out the problem comes from the SocketRocket disconnection.

After PTPusherConnection calls [socket close]; in the - (void)disconnect method, SocketRocket's delegate method - (void)webSocket:(SRWebSocket *)webSocket didCloseWithCode:(NSInteger)code reason:(NSString *)reason wasClean:(BOOL)wasClean is called with the following values:

code: 1001
reason: "Stream end encountered"
wasClean: NO

So, I guess the error comes from the way Pusher closes the socket, or maybe it's a SocketRocket bug. There's a related issue opened in their repo. What do you think, @lukeredpath?

Any updates on this issue? Or any work arounds? Causing major problems with logout in our app.

Edit: Oops, saw the workaround, must have an issue on my end.

The best workaround is still to build your own flag for this and implement
this delegate method:


- (BOOL)pusher:(PTPusher *)pusher connectionWillAutomaticallyReconnect:(
PTPusherConnection *)connection afterDelay:(NSTimeInterval)delay

{

return self.shouldReconnect;

}

[image: Inline-Bild 1][image: Inline-Bild 2]

2016-01-07 22:49 GMT+01:00 kkendall33 notifications@github.com:

Any updates on this issue? Or any work arounds? Causing major problems
with logout in our app.


Reply to this email directly or view it on GitHub
#196 (comment)
.

Beste Grüße von der byte.it http://lets-byte.it/!

Jan Galler

byte.it http://lets-byte.it/ [Kees Galler] GbR
Richard-Wagner-Str. 33 | 86633 Neuburg an der Donau
E-Mail: jan@lets-byte.it
Telefon: +4915164308607

Thanks! Working well for me. I read the rest of the thread with the work around after I posted my comment.

No problem, we had all the same problem and well… the cause isn't in this
library but in a dependency.

I didn't know about this delegate method too until someone told about in
this thread.

On Thursday, 7 January 2016, kkendall33 notifications@github.com wrote:

Thanks! Working well for me. I read the rest of the thread with the work
around after I posted my comment.


Reply to this email directly or view it on GitHub
#196 (comment)
.

Beste Grüße von der byte.it http://lets-byte.it/!

Jan Galler

byte.it http://lets-byte.it/ [Kees Galler] GbR
Richard-Wagner-Str. 33 | 86633 Neuburg an der Donau
E-Mail: jan@lets-byte.it
Telefon: +4915164308607

This should have been fixed in facebookincubator/SocketRocket#300

We are soon to release a new version using SocketRocket 0.5.1

I checked with SocketRocket 0.5.1 and the problem still occurred.
It just changed the error code from 1001 to 1000 (with PTPusherFatalErrorDomain domain).

How frustrating! Let's reopen for now then.