-
Notifications
You must be signed in to change notification settings - Fork 1
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
fix: Changes for v2.3.0 to fix issues seen with highly concurrent creation of a large number of sockets #21
Conversation
… of a large number of sockets - feat: Add `authTimeout` property to SocketConnector. Previously this was - hard-coded to 5 seconds which is a bit restrictive for slow network connections. It now defaults to 30 seconds but may be set at time of construction - feat: added `authTimeout` parameter to `serverToServer`; this is provided to the SocketConnector constructor - feat: added `backlog` parameter to `serverToServer`; this is provided to the ServerSocket.bind call - feat: added `backlog` parameter to `serverToSocket`; this is provided to the ServerSocket.bind call - fix: reordered some code in `_destroySide` so it handles internal state before trying to destroy sockets - fix: added `catchError` blocks for everywhere we're calling `handleSingleConnection` when wrapped in `unawaited` - More logging (when in verbose mode)
@@ -408,7 +454,8 @@ class SocketConnector { | |||
bool multi = false, | |||
@Deprecated("use beforeJoining instead") | |||
Function(Socket socketA, Socket socketB)? onConnect, | |||
Function(Side sideA, Side sideB)? beforeJoining}) async { | |||
Function(Side sideA, Side sideB)? beforeJoining, | |||
int backlog = 0}) async { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
added this in case we need it in future
); | ||
|
||
StreamController<Socket> ssc = StreamController(); | ||
ssc.stream.listen((sideASocket) async { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The code in this listen closure is identical to what was previously in the serverSocketA.listen closure
|
||
onConnect?.call(sideASocket, sideBSocket); | ||
}); | ||
|
||
// listen on the local port and connect the inbound socket | ||
connector._serverSocketA?.listen((sideASocket) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this closure now chucks the socket onto the other stream controller and returns immediately.
- What I did
Changes for v2.3.0 to fix issues seen with highly concurrent creation of a large number of sockets
- How I did it
serverToSocket
in the serverSocket.listen closure, pass the socket onto another stream controller and immediately return. This ensures that the TCP handshake completion is not delayed by anything to do with the socket_connector codeOther changes
authTimeout
property to SocketConnector. Previously this wasauthTimeout
parameter toserverToServer
; this is provided to the SocketConnector constructorbacklog
parameter toserverToServer
; this is provided to the ServerSocket.bind callbacklog
parameter toserverToSocket
; this is provided to the ServerSocket.bind call_destroySide
so it handles internal state before trying to destroy socketscatchError
blocks for everywhere we're callinghandleSingleConnection
when wrapped inunawaited
- How to verify it
Testing via atsign-foundation/noports#1509