nuclearace / Socket.IO-Client-Swift

socket.io-client for Swift
Other
361 stars 53 forks source link

Task created in a session that has been invalidated? #78

Closed iambatoan closed 8 years ago

iambatoan commented 8 years ago

I always get this exception when I try to connect and disconnect many times, am I wrong or any way to fix this issue? Thank you

nuclearace commented 8 years ago

This has been reported before. I'm going to look into it today

iambatoan commented 8 years ago

It seems not working. I connect and disconnect once, the exception still happens. I saw that property connected is true when i have disconnected already.

nuclearace commented 8 years ago

Are you on the latest version of the client?

iambatoan commented 8 years ago

Yeah, i am on the latest version, just connect and disconnect, then I will get the exception

nuclearace commented 8 years ago

How are you creating the client? Can you give some examle code?

iambatoan commented 8 years ago

I have a singleton to manage the socket, this is my sample code, I have a button that call connect when click, and disconnect when click again

- (void)connectWithSuccess:(void (^ __nonnull)())success {
    [self.socket on:@"connect" callback:^(NSArray* data, SocketAckEmitter* ack) {
        [self findMatch];
    }];

    [self.socket on:@"disconnect" callback:^(NSArray* data, SocketAckEmitter* ack) {
        NSLog(@"disconnected");
    }];

    [self subscribeJoinedRoomWithCallBack:success];

    [self.socket connect];
}

- (void)findMatch {
    [self.socket emit:@"findMatch" withItems:@[]];
}

- (void)disconnect {
    [self.socket disconnect];
}
nuclearace commented 8 years ago

I mean how you're creating the socket

iambatoan commented 8 years ago

Sorry for not understanding your question clearly, here are my sample code

+ (instancetype __nonnull)sharedManager {
    static RCSocketIOManager *instance = nil;
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        instance = [[RCSocketIOManager alloc] init];
        instance.socket = [[SocketIOClient alloc] initWithSocketURL:kBaseSocketURL opts:nil];
    });
    return instance;
}
nuclearace commented 8 years ago

I'll have to look into this more. Not really sure what's going on.

nuclearace commented 8 years ago

Are you trying to connect and disconnect from different dispatch_queues?

iambatoan commented 8 years ago

Same queue, but I notice that the issue only happens on ios 9 device or simulators. In ios 8.x, it works perfectly.

nuclearace commented 8 years ago

Do you have a stack trace or something?

nuclearace commented 8 years ago

I'm having trouble reproducing.

iambatoan commented 8 years ago

I tested in 3 iOS 9.0.1 devices and get the exception, 4 iOS 8.x devices work fine. In iOS 8.x, it only shows the "Attempted to create a task in a session that has been invalidated", but in iOS 9, it shows and crashes. This is the screen shot: http://take.ms/DCiXh

nuclearace commented 8 years ago

I'll look into it later today. You could try forcing polling as a workaround until I figure it out

nuclearace commented 8 years ago

Does the latest master do anything about it?

iambatoan commented 8 years ago

I use cocoapods then the issue seems disappear. Before I dragged the source files to my project for supporting iOS 7.

Uk44 commented 8 years ago

how to cancel almofire download request after doing Manager.sharedInstance.session.invalidateAndCancel() .... this i have getting this error.

Attempted to create a task in a session that has been invalidated 2016-07-02 16:52:57.354 FlydeApp[19981:191244] *\ Terminating app due to uncaught exception 'NSGenericException', reason: 'Task created in a session that has been invalidate