react-native-tcp-socket icon indicating copy to clipboard operation
react-native-tcp-socket copied to clipboard

Occasional App crash: [__NSPlaceholderDictionary initWithObjects:forKeys:count:]: attempt to insert nil object from objects[0]

Open westofpluto opened this issue 1 year ago • 2 comments

Fatal Exception: NSInvalidArgumentException: [__NSPlaceholderDictionary initWithObjects:forKeys:count:]: attempt to insert nil object from objects[0]

This happens in line 191 of TcpSockets.m, called from line 476 in TcpCocketClient.m. My server is a plain old TCP socket server, no TLS.

It is a bug reported by crashlytics so a user experienced this, but I have not been able to reproduce

Specs: iPhone 13 iOS 17.5.1 RN version: 0.69.6 react-native-tcp-sockets: 6.0.6

I notice in TcpSocket.m that you get socket from: GCDAsyncSocket *socket = [client getSocket]; But then you never check to see if it is null. It would best to check for null and if null, send another event to indicate a null socket so that the JS/TS code can respond to that as an error rather than allowing it to crash the app. Of course, I am just guessing here, maybe the socket is ok but its properties are bad? I don't know. In any case, is there any workaround to prevent the app from crashing?

westofpluto avatar Jul 17 '24 23:07 westofpluto

Same. Adding some more traces in case it helps. I will try to figure out what happens but is hard since it's kind of random and hard to reproduce:

[CoreFoundation] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[__NSPlaceholderDictionary initWithObjects:forKeys:count:]: attempt to insert nil object from objects[0]'
*** First throw call stack:
(
0   CoreFoundation                      0x00000001804ae0f8 __exceptionPreprocess + 172
1   libobjc.A.dylib                     0x0000000180087db4 objc_exception_throw + 56
2   CoreFoundation                      0x000000018051c84c -[__NSPlaceholderDictionary initWithObjects:forKeys:count:] + 660
3   CoreFoundation                      0x00000001804ac9cc +[NSDictionary dictionaryWithObjects:forKeys:count:] + 48
4   XXXXX.debug.dylib           0x0000000105f716f0 -[TcpSockets onConnect:] + 512
5   XXXXX.debug.dylib           0x0000000105f6ffc8 -[TcpSocketClient socket:didConnectToHost:port:] + 236
6   XXXXX.debug.dylib           0x0000000105191f6c __29-[GCDAsyncSocket didConnect:]_block_invoke_3 + 64
7   libdispatch.dylib                   0x00000001<…>

landabaso avatar Oct 27 '24 11:10 landabaso

I’ve been reviewing various forks of this repository to identify fixes implemented on other branches. See this one: https://github.com/Rapsssito/react-native-tcp-socket/commit/cb7eb99783c7a88bc52fc80217195fa9bd9daa02

Without a deep familiarity with this repo’s codebase, could this potentially resolve the issue, @Rapsssito ?

EDIT: I've patch-packaged the package with this fix and have not been able to reproduce the crash so far.

landabaso avatar Oct 29 '24 14:10 landabaso