Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Explicit Disconnect causes reconnect #196

Open
letsbyteit opened this issue Nov 5, 2015 · 11 comments
Open

Explicit Disconnect causes reconnect #196

letsbyteit opened this issue Nov 5, 2015 · 11 comments

Comments

@letsbyteit
Copy link

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?

@lukeredpath
Copy link
Contributor

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

@lukeredpath
Copy link
Contributor

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.

@letsbyteit
Copy link
Author

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.

@GorkaMM
Copy link

GorkaMM commented Dec 3, 2015

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?

@kkendall33
Copy link

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.

@letsbyteit
Copy link
Author

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 [email protected]:

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: [email protected]
Telefon: +4915164308607

@kkendall33
Copy link

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

@letsbyteit
Copy link
Author

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 [email protected] 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: [email protected]
Telefon: +4915164308607

jilouc added a commit to jilouc/libPusher that referenced this issue May 24, 2016
Fixes pusher#196 - Explicit Disconnect causes reconnect
(Following changes in SocketRocket facebookincubator/SocketRocket@818cec9)
@hamchapman
Copy link
Contributor

hamchapman commented Jun 29, 2016

This should have been fixed in facebookincubator/SocketRocket#300

We are soon to release a new version using SocketRocket 0.5.1

@dral3x
Copy link

dral3x commented Aug 17, 2016

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).

@hamchapman
Copy link
Contributor

How frustrating! Let's reopen for now then.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants