Rapsssito / react-native-tcp-socket

React Native TCP socket API for Android, iOS & macOS with SSL/TLS support.
MIT License
304 stars 80 forks source link

java.lang.IllegalArgumentException TcpSocketsNo socket with id [X] #120

Closed acb closed 2 years ago

acb commented 2 years ago

Description

I've been getting some automated crash reports delivered to me with this error along with general user reports of frequent network interruptions. The full stack trace is

java.lang.IllegalArgumentException: TcpSocketsNo socket with id 1         at 
com.asterinet.react.tcpsocket.TcpSocketModule.getTcpServer(TcpSocketModule.java:357)         at 
com.asterinet.react.tcpsocket.TcpSocketModule.access$700(TcpSocketModule.java:37)         at 
com.asterinet.react.tcpsocket.TcpSocketModule$4.run(TcpSocketModule.java:147)         at
java.lang.Thread.run(Thread.java:923)         at 
java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)         at 
java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)         at 
java.lang.Thread.run(Thread.java:923)

Steps to reproduce

I haven't been able to reproduce this myself, unfortunately. I don't do anything very special in my setup though, I just run a TCP server and then open up connections to it. The connections just hang out occasionally sending and receiving packets. My users have reported that the connection seems to drop a lot and my error handling code automatically reconnects them.

Current behavior

Client sockets apparently sometimes crash.

Expected behavior

Sockets stay open without error.

Relevant information

OS Android, various versions (8-11)
react-native 0.63.3
react-native-tcp-socket 5.2.1
Adnan48 commented 2 years ago

I am facing this error when I am trying to connect to 30+ devices, if some devices are not connected it gives error and tries to close the socket.this is where the app crashes and I get the error.

Rapsssito commented 2 years ago

@acb @Adnan48, I am sorry for your issue, but I need a minimal reproducible example code so I can work on a fix. could you provide one?

github-actions[bot] commented 2 years ago

Hey there, it looks like there has been no activity on this issue recently. Has the issue been fixed, or does it still require the community attention? This issue may be closed if no further activity occurs.

pajkho commented 1 year ago

Hi!

I'm facing the same issue. Could it be because the error in the below method is never catched inside the write method?

private TcpSocketClient getTcpClient(final int id) { TcpSocket socket = socketMap.get(id); if (socket == null) { throw new IllegalArgumentException("No socket with id " + id); } if (!(socket instanceof TcpSocketClient)) { throw new IllegalArgumentException("Socket with id " + id + " is not a client"); } return (TcpSocketClient) socket; }