-
Notifications
You must be signed in to change notification settings - Fork 154
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Receiving "Address Already in Use" error when binding two sockets to same port on iOS #53
Comments
The fix appears to work really well. No more errors of this kind were encountered after implementation. |
Can someone please follow up this. This issue happens very often to my app when another app is also using UDP and being kill by OS in the background(you can see from the multi-task screen). I think somehow OS wakes up the other app and that app binds the port, so my app using this library can't bind the port. Have used "enableReusePort", but it didn't help. |
I have tried:
update: |
Hi @intmainvoid , did you find a solution for this? I'm using the CocoaAsyncSocket. This issue happens very often to my app when another app is also using UDP and being kill by OS in the background(you can see from the multi-task screen). I think somehow OS wakes up the other app and that app binds the port, so my app using this library can't bind the port. Have used "enableReusePort", but it didn't help. |
@quhaoran007 - Yes I did. This PR fixed the problem: #54. You might still see "Address already in use" in your logs but it won't be a fatal error and that application will behave as intended. Make sure you set the reusePort option to true like so dgram.createSocket({
type: 'udp4',
reusePort: true
}).bind('127.0.0.1', (err) => {
console.log("Connected Successfully?: ", err ? "false" : "true");
}); |
@intmainvoid Do you if that bug has been fixed in the original CocoaAsyncSocket lib? Because I'm using CocoaAsyncSocket and the last time I tried with reusePort = true and which has no effect. Thanks |
The original CocoaAsyncSocket lib that has been included in this library contains all the necessary logic to support the SO_REUSEPORT option. See /~https://github.com/tradle/react-native-udp/blob/master/ios/CocoaAsyncSocket/GCDAsyncUdpSocket.h#L493. For react-native-udp this option is set in the bridging module: /~https://github.com/tradle/react-native-udp/blob/master/ios/UdpSocketClient.m#L100. Everything is there and we are using in production on one heavily tested project. Maybe you could post your sample code here that isn't working? |
@intmainvoid : looks like port/address reuse is done specifically for iOS Any suggestion for Android ?
|
My apologies, reuse address seem to be So with that being true, what could be the reason for the error/crash? from crashlytics:
Any help will be appreciated. |
@rimzici Did you find out a solution for the issue? |
The Problem:
If two sockets running in the same app try to bind to the same port, an error occurs to the tune of:
Proposed Solution (for iOS):
GCDAsyncUdpSocket needs updating and react-native-udp needs to make use of
enableReusePort:flag:error:
Proposed Solution (for Android):
TBC - (not even sure it is a problem)
More info here: robbiehanson/CocoaAsyncSocket#422
Will test the proposed solution for iOS ASAP and post results here.
The text was updated successfully, but these errors were encountered: