thaliproject / Thali_CordovaPlugin

Thali p2p plugin
MIT License
226 stars 44 forks source link

ThaliCore: TCPListener "Address already in use" doesn't trigger the retry logic #1942

Open enricogior opened 6 years ago

enricogior commented 6 years ago

In ThaliCore we added a retry logic for transient errors, we need to figure out if we can recover from this error:

[ThaliCore] TCPListener.startListeningForConnections(on:connectionAccepted:completion:)
failed, error:Error Domain=NSPOSIXErrorDomain Code=48 "Address already in use" 
UserInfo={NSLocalizedDescription=Address already in use, 
NSLocalizedFailureReason=Error in bind() function}
2017-07-18 07:16:46 - DEBUG thaliMobileNativeWrapper: 'multiConnectResolved: 
{"syncValue":"0","error":"Connection could not be established","portNumber":0}'
enricogior commented 6 years ago

Another issue with this error is that TCPListener.startListeningForConnections() doesn't return an error to its direct caller, in this case is BrowserRelay.openRelay(), therefore the relay is not released.

enricogior commented 6 years ago

Note: we use the GCDAsyncSocket library that seems to set SO_REUSEADDR We need to verify if that covers our case.