Enable decoupling of acceptClientConnection and delegate.onAccept #85
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
I have introduced an optional parameter
invokeDelegate
toacceptClientConnection()
, that can be used to defer the invocation ofdelegate?.onAccept(socket)
.A new function,
invokeDelegateOnAccept(socket)
is introduced to perform the call to the delegate, which will either be called byacceptClientConnection(invokeDelegate: true)
(equivalent to the previous behaviour), or by the application directly following a call toacceptClientConnection(invokeDelegate: false)
.Motivation and Context
The delegate.onAccept() function may block until the client transmits the SSL handshake. In the case of a badly behaved client (trivially,
telnet localhost <ssl port>
), this could be indefinite.Since the only way for the application to know whether an incoming connection is available to be accepted is to block on
acceptClientConnection()
, this effectively leads to preventing any further connections from being accepted when a badly behaved client connects.By decoupling the accept and the SSL_accept parts of the process, there is an opportunity to perform the latter on a separate thread, to avoid blocking the main listener thread, which can continue to loop around
acceptClientConnection()
.Resolves Kitura/BlueSSLService#40
How Has This Been Tested?
I ran the Socket tests 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 (with an appropriate change to Kitura-net) that, when creating a bad connection (as described above), the listener was no longer prevented from accepting further well-behaved connections.
Checklist: