Skip to content
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

Merged
merged 3 commits into from
Nov 11, 2024

Conversation

gkc
Copy link
Contributor

@gkc gkc commented Nov 8, 2024

- 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

  • fix: in 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 code

Other changes

  • 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)

- How to verify it
Testing via atsign-foundation/noports#1509

… 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)
@gkc gkc requested review from XavierChanth and cconstab and removed request for XavierChanth November 8, 2024 13:21
@@ -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 {
Copy link
Contributor Author

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 {
Copy link
Contributor Author

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) {
Copy link
Contributor Author

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.

@gkc gkc merged commit a0e4285 into trunk Nov 11, 2024
2 checks passed
@gkc gkc deleted the gkc/2.3.0 branch November 11, 2024 17:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants