react-native-tcp-socket: Connection error never emitted on iOS
Description
Hello!!
I’m trying to create a tcp connection to an incorrect host (the ip is unreachable).
Here is my code:
...
private _device = null
private async openConnection(
host,
dataListenerCallback,
): Promise<void> {
if (this._device) {
this._device.destroy();
}
return new Promise((resolve, reject) => {
this._device = net.createConnection({
port: 53333,
host,
timeout: 1000,
}, (socket) => {
console.log('connected');
resolve();
});
this._device.on('connect', () => {
console.log('connect');
});
this._device.on('connection', () => {
console.log('connnection');
});
this._device.on('error', (error) => {
console.log('Error', error);
reject();
});
this._device.on('data', dataListener);
this._device.on('close', () => {
console.log('Connection closed!');
});
});
Current behavior
this function never rejects or resolves.
Expected behavior
I expected to catch a connection error in the error event listener.
Relevant information
| react-native | 0.61.5 | | react-native-tcp-socket | 3.7.1 |
About this issue
- Original URL
- State: closed
- Created 4 years ago
- Comments: 33 (15 by maintainers)
@mi-mazouz, I am glad it worked! If you agree, I think we can close this issue now. It has been a difficult problem to tackle.
@itzsankar, this issue has +30 comments right now. Could you please create a new issue with your problem, the devices with issues and a reproducible code?
I updated the package to the latest version and tested this code:
and after 1 min and 15secs the error and close events were triggered so that’s a good new.
@mi-mazouz, I have not been able to figure it out yet. I have came into the conclusion that it might be related to
GCDAsyncSocketinner workings. I am still working on it. If you find anything, please let me know.@mi-mazouz, glad it works with
setTimeout()! I am not able to reproduce the issue, the device on your 192.168.1.1 may be accepting the TCP connection and keeping it on hold forever (that’s why you don’t get any error).I will be releasing a
setTimeout()update soon (#56), it should work in all scenarios.@Rapsssito sure, I have created a new issue #106 we can track from there , let me know if you need any details
my bad this_.device.removeListener(‘timeout’) in createConnection callback did the job!
@ewc003, could you create a new issue with your specific problem?
@mi-mazouz, I am able to reproduce the bug on iOS. Working on it.