-
Notifications
You must be signed in to change notification settings - Fork 79
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
IBM-Swift/Kitura#1143 Invoke socket delegate onAccept on a separate thread #219
Conversation
…Accept on a separate thread
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.
LGTM
@djones6 |
@youming-lin I can recreate the failures locally - I'm puzzled as to why I didn't see these before... Investigating. |
Okay, I think the reason I didn't see them before was that some additional checks have been added on top of my original PR for Socket: Kitura/BlueSocket@5c77668 This introduces a check to see whether the call to |
That exception is thrown under two conditions. The first is when the API is called with a Socket that was not returned by an acceptClientConnection(invokeDelegate: false). The second instance is when it's called multiple times for the same Socket. |
The exception in this case is because the socket does not have a delegate. The original change I made to Socket allowed The check does not allow this, as Kitura-net now needs to check whether the socket has a delegate before trying to invoke the new function. |
DispatchQueue.global().async { [weak self] in | ||
if let strongSelf = self { | ||
strongSelf.initializeClientConnection(clientSocket: clientSocket, listenSocket: listenSocket, socketManager: socketManager) | ||
if let _ = listenSocket.delegate { |
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.
if listenSocket.delegate { }
🙂
Through fixing the bug above, I realized that I had added an async invocation for every socket accept, even if there is no delegate (which is unnecessary). I pushed a refactoring that only goes down the async route if the socket has a delegate. I think it also makes it clearer which parts of the process the error handling applies to. |
Codecov Report
@@ Coverage Diff @@
## master #219 +/- ##
==========================================
+ Coverage 73.77% 74.02% +0.24%
==========================================
Files 31 31
Lines 4122 4146 +24
==========================================
+ Hits 3041 3069 +28
+ Misses 1081 1077 -4
Continue to review full report at Codecov.
|
I'm adding a test to cover the original bug. |
Description
This PR decouples the invocation of
delegate?.onAccept()
fromlistenerSocket.acceptClientConnection()
, invoking the former in a separate thread.Note, this depends on Kitura/BlueSocket#85 and the subsequent related changes, tagged in BlueSocket
0.12.67
.Motivation and Context
Resolves Kitura/Kitura#1143
This avoids blocking the listener thread if a badly-behaved client connects to an SSL-enabled listener, which will block in
SSL_accept
until the client transmits an SSL handshake.How Has This Been Tested?
I ran the Kitura-net tests (with Socket branch issue_1143) and they passed.
I tested with a Kitura-based application which uses SSLService, driven under load (50 concurrent clients from wrk) and the application functioned correctly. I tested on both Linux and Mac.
I also verified that, when creating a bad connection (as described above), the listener was no longer prevented from accepting further well-behaved connections.
Checklist: