SSLSocketChannel2: avoid wasting resources if no valid handshake is made #1491
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.
This PR tries to resolve excessive CPU usage and stale socket when a connection is made towards a SSL WebSocket with no proper handshaking.
Description
First commit throttles processHandshake() by 10ms to avoid busy looping and consuming an entire CPU core.
Second commit forcefully closes the socket if no handshake is done under 60s.
Related Issue
#896
Motivation and Context
I'm extremely surprised this isn't resolved yet.
I was debugging an issue on my app that sometimes hogs an entire CPU core up.
This was hard to hunt down as it's not consistent.
I finally narrowed it down to a rogue client trying to connect over to my SSL WebSocket server.
With no valid SSL handshake, it hogged up an entire CPU core indefinitely.
This would be an extremely frequent phenomenon unless the device is strictly limited to a controlled local network.
How Has This Been Tested?
Checklist: