Rapsssito / react-native-tcp-socket

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

java.lang.IllegalArgumentException Tcp Sockets: No socket with id #167

Closed pajkho closed 1 year ago

pajkho commented 1 year ago

Description

Sometimes when the connection gets interrupted while writing data the app will crash with "No socket with id" error. I suspect that this might be due to the write method not catching the errors that is thrown by getTcpClient method.

Steps to reproduce

Steps to reproduce the behavior:

  1. Write on the socket while it simultaneously gets disconnected.

Current behavior

App crashes with error

Expected behavior

Connection can close but app should not crash.

Relevant information

OS no
react-native yes
react-native-tcp-socket yes
Rapsssito commented 1 year ago

@pajkho, this is a common issue if you are trying to use the socket while it has not established a connection yet. Make sure you wait for the connection callback before using the socket.

pajkho commented 1 year ago

The issue arises for us when having continuous writes to the tcp connection which doesn't stop until the end event happens. If the connection closes there can be a gap between the close of the connection and the end event where there is new writes which causes this error and the app crashes.

Wouldn't it be more reasonable to try/catch this to prevent the app from crashing and instead call the error event? It shouldn't be possible to crash the app because you mistakenly try to write to a closed connection.

Rapsssito commented 1 year ago

@pajkho, indeed, I will release a fix ASAP.

github-actions[bot] commented 1 year ago

:tada: This issue has been resolved in version 6.0.6 :tada:

The release is available on:

Your semantic-release bot :package::rocket:

yang-Ann commented 2 days ago

Hello, this fix is missing in version 6.1.0 socketMap.remove(cId);

link

Rapsssito commented 2 days ago

@yang-Ann, this fix is included in the latest version. The solution was to remove socketMap.remove(cId);.

yang-Ann commented 1 day ago

Thank you very much

------------------ 原始邮件 ------------------ 发件人: "Rodrigo @.>; 发送时间: 2024年7月9日(星期二) 下午5:37 收件人: @.>; 抄送: @.>; @.>; 主题: Re: [Rapsssito/react-native-tcp-socket] java.lang.IllegalArgumentException Tcp Sockets: No socket with id (Issue #167)

@yang-Ann, this fix is included in the latest version. The solution was to remove socketMap.remove(cId);.

— Reply to this email directly, view it on GitHub, or unsubscribe. You are receiving this because you were mentioned.Message ID: @.***>