Re: Exception thrown when calling NSConnection connectionWithReceivePort:sendPort:
Hi Ken, Thanks for responding. I probably should have mentioned it, as I had a similar thought (but the message was getting so long I feared no one would read it as it was!) DOConnectionSocket is definitely not nil, I watched the process through the debugger. The port and the host as passing correctly as well; the DOConnectionSocket is created correctly both on the first pass and second in other words. Right now I'm trying to test bringing DO up and down, I haven't introduced the step of truly taking the LAN off and back online yet, so I don't believe that availability is the problem. That'll be phase 2, but I have to prove that this concept works first =) Chris Backas On Jul 22, 2008, at 7:16 PM, Ken Thomases wrote: On Jul 22, 2008, at 10:46 AM, Chris Backas wrote: So... the problem is that when I try to reconnect to DO, meaning, call getServerProxy the second time, I get an exception from the DOConnection = [[NSConnection connectionWithReceivePort:nil sendPort:DOConnectionSocket] retain]; line. The exception: *** -[NSCFArray insertObject:atIndex:]: attempt to insert nil The backtrace: #0 0x971f30d7 in objc_exception_throw () #1 0x94fc3f2b in +[NSException raise:format:arguments:] () #2 0x94fc3f6a in +[NSException raise:format:] () #3 0x900ea3d0 in _NSArrayRaiseInsertNilException () #4 0x90008a04 in -[NSCFArray insertObject:atIndex:] () #5 0x90008914 in -[NSCFArray addObject:] () #6 0x90027d2d in -[NSConnection addRunLoop:] () #7 0x90027b8f in -[NSConnection initWithReceivePort:sendPort:] () #8 0x90042df7 in +[NSConnection connectionWithReceivePort:sendPort:] () #9 0x001ecae7 in -[FourDForwarder getServerProxy] (self=0x6be210, _cmd=0x1f401c) *snip* The exception is internal, but I have to think that it's occurring because of some state I'm not appropriately cleaning up when I disconnect. I just can't think what that would be. It's related to runloops based on the backtrace, and the NSConnection documentation says that it tries to register with the "Current" run loop. NSRunLoop's documentation says that if you ask for the current run loop and there isn't one, one will be created though... So I can't see a situation where it would be trying to add a nil run loop. Any ideas? I suspect that DOConnectionSocket is nil. Have you tried logging it? While you're at it, try logging the arguments to the initialization of that port object: the port and host. Is anything written to the stderr/stdout/console immediately prior to this exception? If the LAN connection was temporarily disconnected, it may be that you're having a domain name resolution failure. Also, you can try using NSHost and/or SCNetworkCheckReachabilityByName to see if the system believes the remote host is "reachable" (for a certain limited meaning of that term; it just means, does the local host know how to route attempts to communicate with that remote host?). Cheers, Ken ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/cocoa-dev/chb%40infoplusonline.com This email sent to [EMAIL PROTECTED] ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to [EMAIL PROTECTED]
Re: Exception thrown when calling NSConnection connectionWithReceivePort:sendPort:
On Jul 22, 2008, at 10:46 AM, Chris Backas wrote: So... the problem is that when I try to reconnect to DO, meaning, call getServerProxy the second time, I get an exception from the DOConnection = [[NSConnection connectionWithReceivePort:nil sendPort:DOConnectionSocket] retain]; line. The exception: *** -[NSCFArray insertObject:atIndex:]: attempt to insert nil The backtrace: #0 0x971f30d7 in objc_exception_throw () #1 0x94fc3f2b in +[NSException raise:format:arguments:] () #2 0x94fc3f6a in +[NSException raise:format:] () #3 0x900ea3d0 in _NSArrayRaiseInsertNilException () #4 0x90008a04 in -[NSCFArray insertObject:atIndex:] () #5 0x90008914 in -[NSCFArray addObject:] () #6 0x90027d2d in -[NSConnection addRunLoop:] () #7 0x90027b8f in -[NSConnection initWithReceivePort:sendPort:] () #8 0x90042df7 in +[NSConnection connectionWithReceivePort:sendPort:] () #9 0x001ecae7 in -[FourDForwarder getServerProxy] (self=0x6be210, _cmd=0x1f401c) *snip* The exception is internal, but I have to think that it's occurring because of some state I'm not appropriately cleaning up when I disconnect. I just can't think what that would be. It's related to runloops based on the backtrace, and the NSConnection documentation says that it tries to register with the "Current" run loop. NSRunLoop's documentation says that if you ask for the current run loop and there isn't one, one will be created though... So I can't see a situation where it would be trying to add a nil run loop. Any ideas? I suspect that DOConnectionSocket is nil. Have you tried logging it? While you're at it, try logging the arguments to the initialization of that port object: the port and host. Is anything written to the stderr/stdout/console immediately prior to this exception? If the LAN connection was temporarily disconnected, it may be that you're having a domain name resolution failure. Also, you can try using NSHost and/or SCNetworkCheckReachabilityByName to see if the system believes the remote host is "reachable" (for a certain limited meaning of that term; it just means, does the local host know how to route attempts to communicate with that remote host?). Cheers, Ken ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to [EMAIL PROTECTED]
Exception thrown when calling NSConnection connectionWithReceivePort:sendPort:
Hello all, This is a little long, the error is summarized at the bottom for anyone who wants to skip ahead though ;) I have an application which is using Distributed Objects to ask a remote machine to obtain and interact with certain resources on its behalf. This has been working great so far, but recently I've been trying to add a new feature to the application. It needs to contact the remote resource over DO, perform some actions, then take down DO (Because it will be going off-LAN temporarily), perform some actions, THEN reconnect to DO and finish with the remote resource. It's the 'reconnect' part that I'm having trouble with. Let me share some code first though, the error will be at the end. Here is the code I'm using to connect DO and obtain the remote root proxy: -(id)getServerProxy { id ReturnMe = nil; @try { // Establish a connection to the server DOConnectionSocket = [[NSSocketPort alloc] initRemoteWithTCPPort: [self getHostPort] host:[self getHost]]; DOConnection = [[NSConnection connectionWithReceivePort:nil sendPort:DOConnectionSocket] retain]; // If the connection was succesful.. if (DOConnection != nil) { // Setup connection parameters [DOConnection enableMultipleThreads]; // Allow a good long time for lengthy DB queries to complete [DOConnection setRequestTimeout:60]; [DOConnection setReplyTimeout:60]; // Register to be notified if the connection dies [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(connectionDidDie:) name:NSConnectionDidDieNotification object:DOConnection]; } ReturnMe = [DOConnection rootProxy]; } @catch(NSException* error) { // Can't do much. Possibly a timeout? NSLog(@"Failed to get Server Proxy! %@",error); ReturnMe = nil; } return ReturnMe; } Here's the code I use to shut down DO: -(void)disconnectDO { connectionOpened = NO; @synchronized(self) { // Clean up and get rid of both proxy objects, but hang onto our connection ID // So that we can seamlessly reconnect if possible [serverProxyObject release]; serverProxyObject = nil; [connectionProxyObject release]; connectionProxyObject = nil; // Take down the connection too [[NSNotificationCenter defaultCenter] removeObserver:self name:NSConnectionDidDieNotification object:DOConnection]; [DOConnection invalidate]; [DOConnectionSocket invalidate]; [DOConnection release]; DOConnection = nil; [DOConnectionSocket release]; DOConnectionSocket = nil; } } So... the problem is that when I try to reconnect to DO, meaning, call getServerProxy the second time, I get an exception from the DOConnection = [[NSConnection connectionWithReceivePort:nil sendPort:DOConnectionSocket] retain]; line. The exception: *** -[NSCFArray insertObject:atIndex:]: attempt to insert nil The backtrace: #0 0x971f30d7 in objc_exception_throw () #1 0x94fc3f2b in +[NSException raise:format:arguments:] () #2 0x94fc3f6a in +[NSException raise:format:] () #3 0x900ea3d0 in _NSArrayRaiseInsertNilException () #4 0x90008a04 in -[NSCFArray insertObject:atIndex:] () #5 0x90008914 in -[NSCFArray addObject:] () #6 0x90027d2d in -[NSConnection addRunLoop:] () #7 0x90027b8f in -[NSConnection initWithReceivePort:sendPort:] () #8 0x90042df7 in +[NSConnection connectionWithReceivePort:sendPort:] () #9 0x001ecae7 in -[FourDForwarder getServerProxy] (self=0x6be210, _cmd=0x1f401c) *snip* The exception is internal, but I have to think that it's occurring because of some state I'm not appropriately cleaning up when I disconnect. I just can't think what that would be. It's related to runloops based on the backtrace, and the NSConnection documentation says that it tries to register with the "Current" run loop. NSRunLoop's documentation says that if you ask for the current run loop and there isn't one, one will be created though... So I can't see a situation where it would be trying to add a nil run loop. Any ideas? Thanks! Chris Backas ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to [EMAIL PROTECTED]