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

Host not reachable error handling

Open sudray opened this issue 2 years ago • 6 comments

Description

Hi I have been evaluating your module as an update for some older react-tcp code and it performs well. Great job and good work in keeping the calls similar to the Node "net"module. Makes for easy use and implementation.

I am an embedded programmer and have decent knowledge of embedded tcp/ip sockets in the micro-controller domain.

My react native app creates multiple tcp clients, all connecting to some hardware and exchanging data. All events such as connect() / data() / close() / error() ) work perfectly well and I have created and connected up to 30 simultaneous clients with no issues at all in iOS & Android.

Steps to reproduce

If some or all servers are OFF and not reachable on the network, the iOS version tries to connect and then has an error and subsequently the close event destroys the client and our routine tries to reconnect again...and all is well.....

In android ( when some or all servers ore OFF ) an error is called within 3 seconds of the connect() function ( even though the connect timeout is set to 5 seconds or greater ) and then an error followed by close occurs. Our code is setup to reconnect and tries but eventually after a few minutes the app crashes.

The effect is more pronounced when more client sockets are trying to connect to unreachable servers. I have even tried adding a 10 second delay after socket.destroy and connecting again, to no avail...

Current behavior

If the server is offline or down or unreachable the app crashes The error is occurring at java level and i do not have a screenshot right now but will share one asap

Expected behavior

The error() event should fire followed by the close() event

Relevant information

React Native 0.64 Xcode 13 Android studio 2021.1.1

Notes

Would love to hear what the possible issues could be and if any possible solutions suggested. Will share any further details as required, and would love to sponsor your work ( for basic prioritized bug support )

Cheers !!

sudray

sudray avatar Aug 16 '21 17:08 sudray

@sudray, I am sorry for your issue. Could you provide a minimal reproducible example code so I can test it in my local setup?

Rapsssito avatar Aug 23 '21 12:08 Rapsssito

@sudray, I am sorry for your issue. Could you provide a minimal reproducible example code so I can test it in my local setup?

please clear me if I am wrong this happens on android I am connecting the client and using the keepalive boolean to be true

const socketClient = TcpSocket.createConnection(
    {
      port: portNumber,
      host: ipAddress,
      timeout: 3000,
    },
    onClientConnected,
  );
  socketClient.setKeepAlive(true, 2000);

if I closed the server app any time, immediately the client raises a close event and this is great but if disconnect the internet from the server app the client app is still working and even sending data to the server dropped connection is working and the client finds everything is okay after some time, minutes, or sometimes more, the client raises an error is this is the expected scneareo? and if it's how can I detect that the server is down or not reachable from the client, is it related to this issue of host not reachable error handing?

Mohamed-kassim avatar Sep 22 '21 19:09 Mohamed-kassim

@Rapsssito Any Information?

Mohamed-kassim avatar Sep 27 '21 13:09 Mohamed-kassim

@Mohamed-kassim, sorry for my late reply. I am working on handling the same errors on iOS and Android. I will close this issue as soon as this is fixed!

Rapsssito avatar Oct 05 '21 12:10 Rapsssito

@Rapsssito no problem, currently, I am syning the server manually with interval and waits for ack to detect when it's down as a workaround https://blog.stephencleary.com/2009/05/detection-of-half-open-dropped.html hope you can finish this soon, Thanks for your efforts

Mohamed-kassim avatar Oct 07 '21 11:10 Mohamed-kassim

@Mohamed-kassim could you please share how you solve your problem?

siarheipashkevich avatar Apr 09 '23 20:04 siarheipashkevich