You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Calling socket.destroy() doesn't work if the timeout timer timed out while connecting. It has no effect. This means we still get the error event later, when it actually times out.
returnnewPromise<void>((resolve,reject)=>{constsocket=TcpSocket.createConnection({host: '192.168.0.70',port: 1337,},()=>{socket.write(payload,'binary',err=>{// TODO})},).setTimeout(5000)socket.on('timeout',()=>{socket.destroy()// Has no effectreject(newError('Timed out'))})// Gets called some time after the `timeout` callbacksocket.on('error',err=>{socket.destroy()reject(err)})})
Notice the timestamps:
Relevant information
OS
iOS
react-native
0.65.1
react-native-tcp-socket
6.0.3
The text was updated successfully, but these errors were encountered:
Tested using patch-package and removing the this._pending check gives me the desired result.
PR: #169
patch-package:
diff --git a/node_modules/react-native-tcp-socket/src/Socket.js b/node_modules/react-native-tcp-socket/src/Socket.js
index 51ca3d6..4268015 100644
--- a/node_modules/react-native-tcp-socket/src/Socket.js
+++ b/node_modules/react-native-tcp-socket/src/Socket.js
@@ -305,7 +305,7 @@ export default class Socket extends EventEmitter {
* Ensures that no more I/O activity happens on this socket. Destroys the stream and closes the connection.
*/
destroy() {
- if (this._pending || this._destroyed) return this;
+ if (this._destroyed) return this;
this._destroyed = true;
this._clearTimeout();
Sockets.destroy(this._id);
Description
Calling
socket.destroy()
doesn't work if the timeout timer timed out while connecting. It has no effect. This means we still get theerror
event later, when it actually times out.I think its because of this
this._pending
check here?https://github.com/Rapsssito/react-native-tcp-socket/blob/master/src/Socket.js#L308
Notice the timestamps:
Relevant information
The text was updated successfully, but these errors were encountered: